Design a tiny URL or URL shortener
Submissions: 3310   Accuracy:


  Difficulty: Medium   Marks: 4
Associated Course(s):   Interview Preparation

Design a system that takes big URLs like “” and converts them into a short 6 character URL. It is given that URLs are stored in database and every URL has an associated integer id.  So your program should take an integer id and generate a 6 character long URL. 

A URL character can be one of the following
1) A lower case alphabet [‘a’ to ‘z’], total 26 characters
2) An upper case alphabet [‘A’ to ‘Z’], total 26 characters
3) A digit [‘0′ to ‘9’], total 10 characters

There are total 26 + 26 + 10 = 62 possible characters.

So the task is to convert an integer (database id) to a base 62 number where digits of 62 base are "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"


The first line of input contains an integer T denoting the number of test cases.

And the second line consists of a long integer.


Print the shortened string in the first line and convert the shortened string back to ID (to make sure that your conversion works fine) and print that in the second line.


1 ≤ T ≤ 70
1 ≤ N ≤ 4,294,967,295








** For More Input/Output Examples Use 'Expected Output' option **

Author: madhuradlakha

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.