Title: How to design a tiny URL or URL shortener? Source: www.geeksforgeeks.org
How to design a system that takes big URLs like “http://www.geeksforgeeks.org/count-sum-of-digits-in-numbers-from-1-to-n/” 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.
One important thing to note is, the long url should also be uniquely identifiable from short url. So we need a Bijective Function
Java solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* http://www.geeksforgeeks.org/how-to-design-a-tiny-url-or-url-shortener/ */ //Given the database unique id of an url //convert it into tiny url class TinyUrl { public String idToTinyUrl(int id) { String map = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; StringBuilder tinyUrl = new StringBuilder(); while(id>0) { tinyUrl.append(map.charAt(id%62)); id /= 62; } return tinyUrl.reverse().toString(); } public int tinyUrlToId(String tinyUrl) { int id = 0; String map = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; for(int i=0;i<tinyUrl.length();i++) { id = (id*62) + map.indexOf(tinyUrl.charAt(i)); } return id; } public static void main(String args[]) { int id = 12345; TinyUrl t = new TinyUrl(); System.out.println(t.idToTinyUrl(id)); System.out.println(t.tinyUrlToId("dnh")); } } |
Currently it sounds like Movable Type is the top blogging platform available right now.
(from what I’ve read) Is that what you’re using on your blog?
we are not sure what you mean by “Movable Type” platform? Could you please be a little bit more elaborate?
Hey there this is somewhat of off topic but I was wondering if
blogs use WYSIWYG editors or if you have to manually code with HTML.
I’m starting a blog soon but have no coding skills so I wanted to get
guidance from someone with experience. Any
help would be greatly appreciated!
Hi,
Yes blogs do use WYSIWYG editors. All popular ones, namely: Blogspot, WordPress etc. have such editors.
-Thanks
Coddicted
After exploring a few of the articles on your web page, I honestly appreciate your way
of blogging. I added it to my bookmark webpage list and will be checking back in the near future.
Please visit my web site too and tell me what you think.
This article will assist the internet users for setting up new
weblog or even a blog from start to end.
Thanks Suzanne.
It’s really a nice and helpful piece of info.
I am satisfied that you simply shared this useful information with us.
Please stay us informed like this. Thanks for sharing.
Cool blog! Is your theme custom made or did
you download it from somewhere? A theme like yours with a few
simple tweeks would really make my blog
jump out. Please let me know where you got your design. Appreciate it
Hi, I do think this is a great site. I stumbledupon it ;)I will
come back once again since I saved as a favorite it. Money and freedom is the best
way to change, may you be rich and continue to guide others.
Your method of describing everything in this post is in fact pleasant, every one be able to simply know it, Thanks a lot.
Howdy! I know this is somewhat off topic but I was wondering which blog platform aare you using for this
website? I’m getting sick and tired of WordPress because I’ve had
problems with hackers and I’m looking at options for another platform.
I would be greqt iff you could point me iin the direction off a good platform.
URL shortening is used to create shorter aliases for long URLs. We call these shortened aliases “short links.” Users are redirected to the original URL when they hit these short links. Short links save a lot of space when displayed, printed, messaged, or tweeted. Additionally, users are less likely to mistype shorter URLs.
Good post! We will be linking to this great content on our site.
Keep up the great writing.
Outstanding post however I was wanting to know if you could write a litte more on this topic?
I’d be very thankful if you could elaborate a
little bit more. Appreciate it!
Hey There. I found your blog using msn. Thiis is a realky
well written article. I’ll be sure tto bookmark it and return to read more
of your useful information. Thanks for the post. I will cwrtainly return.
Amazing! This blog looks exactly like my old one! It’s on a totally different topic but it has pretty much the same layout and design. Wonderful choice of colors!
Good way of explaining, and fastidious article to take information regarding my presentation subject, which i am
going to deliver in academy.
I was recommended this web site by my cousin. I am not sure whether this post is written by him as no one else know such detailed about my difficulty.
You’re wonderful! Thanks!
It is not my first time to go to see this site, i am browsing this site dailly and take fastidious information from here daily.
Do you mind if I quote a few of your posts as long
as I provide credit and sources back to your webpage?
My blog site is in the very same niche as yours and my visitors would genuinely benefit from
a lot of the information you provide here. Please let me
know if this alright with you. Regards!
sure
It’s great that you are getting thoughts from this piece of writing as well as from our discussion made here.
Hello, Neat post. There is an issue along with your site in web
explorer, would test this? IE still is the market chief and a large section of other people will miss your excellent writing due to this problem.
If some one desires expert view regarding running a blog afterward
i recommend him/her to pay a visit this weblog, Keep up the fastidious job.