NOTE: Some of the solutions mentioned below may need some tweaking for boundary cases. Most of my blog-articles related to Technical Interview Questions will be like that. This is to ensure that students do NOT mug up the solutions, rather, they discuss them and learn. Also, not everyone can learn everything at the same time. Depending on my mood, I may write a continuation of this post someday. But for now, you will have to think about the boundary cases where some of the methods mentioned below may fail. And I have knowingly, not mentioned, the best and the coolest solutions that I know!
This is to see if students really figure them out by themselves. I know many will read this blog-article before interviews, so I would like to see if they can come up with any other solution. Also, even if they do read this post, it will show that they really worked hard to learn to crack the interview, which will also count as a positive. However, if someone thinks that he can outsmart interviewers by mugging these things, then s/he will be trapped in a follow up question!