Please navigate to the bottom of the page for Table of Contents

Monday, November 18, 2013

How to answer algorithmic programming interview questions

Most technical programming interviews have at least one or more programming whiteboard exercise. These generally include questions like
1. Write an algorithm to reverse a linked list.
OR
2. Write a function to sort a binary tree.
OR
3. Write an algorithm to remove duplicates and sort an arbitrary long input string comprised of single digit numbers.

Almost all of such questions require you to explain your thinking on whiteboard and then design and explain your algorithm or function on the whiteboard in real time. So how do you answer algorithmic questions and make sure that your thinking and direction covers various different aspects that an interviewer is looking for.

Here is one such list that you can keep at the back of your mind when attempting to solve such questions. Some of them may not be valid for some questions, but you should try to model your answer around these tenets.

Understand the question: Make sure you repeat the question. The goal is to understand exactly what the interviewer is looking for in your answer. 

Asks clarifying questions to understand what the interviewer is looking for: This is an extension of the first point. You need to ask as many clarification questions as necessary to make sure you are solving the right problem. Most questions will have ambiguity built into them and it is your job to make sure you get them clarified.


Paraphrase the problem: Once you have clearly understood the question, paraphrase it. This helps make sure to the interviewer that you really get the question and the subtleties associated with it. 


Call out assumptions: Before and as you are designing the algorithm, make sure to clearly spell out any assumptions that you are making. For example, array index starts at 0, the input is assumed to be made only of numbers, etc. Unsaid assumptions have a bad habit of coming back and biting you later in the exercise.


Articulate at least one or two acceptable input and output: If possible, it is always good to show one or two possible input cases and the desired output from your solution. This helps both you and interviewer to make sure that you are on track to understanding the question.


Define broad solution: Once you have reached this stage, define a broad outline of the solution. No code, just the big ticket steps. For example, Sort the input, find the most common elements, use hashmaps, clean output to remove duplicates, etc.


Define possible other solutions (using hashtags, linked lists, trees, etc): Once you have a broad solution, make sure that you discuss or highlight some alternative approaches. This shows that you can think from a higher perspective and evaluate alternate approaches.


Draw a “manual run” on the whiteboard for input/output: To make sure that your high level solution really works, manually run your input through that to make sure you get the desired output.


Define the high level design: Now is the time to start hashing out your high level design components. Basic functions, data structures, core logic. A lot of your time would be spent here understanding and building your design.


Define the basic algorithm: Here you would be defining the core logic and algorithm for your problem. Make sure you keep talking about your approach.


Discuss time taken by algorithm (1, log(n), etc): Once you have the detailed design in place, discuss the performance characteristics of your solution. Think about minor tweaks or improvements you can do here to improve the performance. 


Talk about error handling: This is very important. You should at least talk about different error conditions and how your algorithm would handle it. You can keep the whiteboard clean by not writing every possible case, but make sure you talk about them.


Handle edge cases: Any good algorithm handles edge cases without going through the entire process very fast. Make sure you spend a few minutes thinking and articulating about them.

Testing: Once you think you have the final design ready, force yourself to turn-off your brain and run a couple of inputs through the algorithm. Follow exact steps there and do not use your brain. Basically, be the computer and test. Test. Test again. You will surely uncover a few things here that you might have missed (e.g. <= instead of ==).


Regularly check in to see if the interviewer is on the same page as you: This is a very important step and needs to be done through out the interview. You need to keep the interviewer engaged and focused. Speak clearly, slowly, think aloud and make sure interviewer is following you.


Hopefully this will help you answer algorithmic programming interview questions in a much better cleaner way using a templated approach.

In the next post we will look at such a templated approach to solving design interview questions.

92 comments:

  1. Replies
    1. Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.Keep the good work going on!!

      ETL Testing training in chennai| SAP MM training in chennai | Informatica training in chennai

      Delete
  2. There are lots of information about hadoop have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get to the next level in big data. Thanks for sharing this. Hadoop Training in Chennai | Big Data Training in Chennai

    ReplyDelete
  3. The strategy you have posted on this technology hepled me to get into the next level and had lot of informations in it.
    salesforce training in chennai | salesforce training institute in chennai

    ReplyDelete
  4. The strategy you have posted on this technology hepled me to get into the next level and had lot of informations in it. SAS is one of the basic level programming and is very important in the analysis process.
    SAS Training in Chennai | SAS Course in Chennai

    ReplyDelete
  5. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us.


    Base SAS Training in Chennai

    ReplyDelete
  6. Thanks for sharing this informative content which provided me the required information about the latest technology.
    Salesforce training in Chennai | Salesforce course in Chennai

    ReplyDelete
  7. Hi, Really your post was very informative. Today's internet era learn Hadoop Online Training will helps you to reach your goal.Selenium Online Training

    ReplyDelete
  8. Nice sharing. R is a language and environment for statistical computing and graphics. Want to make a career in R Programming. Learn R Programming Online Training course @ GangBoard. We are the best provider of online training on evergreen technologies.

    ReplyDelete
  9. Thank you for this valuable information. I have got some important suggestions from it. Get your business to the next level in simple steps.
    ERP Software Solutions in Chennai.

    ReplyDelete
  10. Thank you for Sharing. I'm working in brave technologies private limited, We are the best erp software developers based in chennai. erp providers in chennai

    ReplyDelete
  11. Nice post. Very interesting to read. Thank you for Sharing.
    erp in chennai

    ReplyDelete
  12. Wonderful blog! I found it while searching on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Many thanks.
    2048 online | tanki online 3

    ReplyDelete
  13. Hi, you have given really informative post. Thanks for sharing this post to our vision. Learn Dotnet will helps you to reach your goal. Dot Net Training in Chennai
    Android Training in Chennai
    Selenium Training in Chennai
    Hadoop Training in Chennai

    ReplyDelete

  14. The blog or and best that is extremely useful to keep I can share the ideas of the future as this is really what I was looking for, I am very comfortable and pleased to come here. Thank you very much.
    animal jam | five nights at freddy's | hotmail login

    ReplyDelete
  15. I would like to say thank you for the amazing details and concepts you are sharing in this.
    Webseiten Gestaltung Lüdenscheid

    ReplyDelete
  16. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. IOT is one such technology where all the things communicate through the cloud, make decisions, and share information. To know more about the course there are many training institutes who provide complete IOT Training effectively

    ReplyDelete
  17. The website is looking bit flashy and it catches the visitors eyes. A design is pretty simple .
    office 2010 professional plus key deutsch

    ReplyDelete
  18. Thanks for one marvelous posting! I enjoyed reading it; you are a great author. I will make sure to bookmark your blog and may come back someday. I want to encourage that you continue your great posts, have a nice weekend!

    Data Science Training in Chennai

    ReplyDelete
  19. Well Said, you have provided the right info that will be beneficial to somebody at all time. Thanks for sharing your valuable Ideas to our vision.. Graphic Designing Training with placement in Chennai | Multimedia Training with Placement in Chennai

    ReplyDelete
  20. Your website content nice nice and interesting to observe.
    Internet Marketing Dienstleistungen

    ReplyDelete
  21. Interesting post! This is really helpful for me. I like it! Thanks for sharing!
    Mobile application developers in Chennai | PHP developers Chennai

    ReplyDelete

  22. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    java training in bangalore

    ReplyDelete
  23. Great post.Thanks for one marvelous posting! I enjoyed reading it;The information was very useful.Keep the good work going on!!

    ETL Testing training in chennai| SAP MM training in chennai | Informatica training in chennai

    ReplyDelete
  24. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.
    white label website builder

    mobile website builder

    ReplyDelete
  25. Thanks for sharing the useful information, I hope these are enough to face an interview with an ease...
    Best Online Software Training Institute | Big Data Analytics Training

    ReplyDelete
  26. Nice post.Thank you so much for sharing.Yiioverflow is a web development company.We have well expert team in Angular JS, Ionic, Yii Framework, Node JS, Laravel, PHP, MySQL, and WordPress.If you want a developer visit.. https://yiioverflow.com/

    ReplyDelete
  27. I just want to tell you that Iím all new to blogging and site-building and really loved your web page. Very likely Iím want to bookmark your site . You amazingly have remarkable posts. Thanks a bunch for sharing your blog.
    Regards - www.office.com/setup
    www.office.com/setup

    ReplyDelete
  28. Thanks for splitting your comprehension with us. It’s really useful to me..Embedded Project Center in Chennai | Embedded Project Center in Velachery

    ReplyDelete
  29. Great post. Wonderful information and really very much useful. Thanks for sharing and keep updating.
    java training in chennai
    java course in chennai

    ReplyDelete
  30. Hey, Wow Provided Post will be Very much Informative to the People Who Visit this Site. Good Work! Thank You for Sharing.
    manufacturing erp software in chennai

    ReplyDelete
  31. Thanks for sharing the interview Q&A.Appreciation for really being thoughtful and also for deciding on certain marvelous guides most people really want to be aware of.

    Spark Training in Chennai
    Spark with Scala Training in Chennai

    ReplyDelete
  32. Our digital marketing course in Chennai is targeted at those who are desirous of taking advantage of career opportunities in digital marketing. Marketing professionals who are presently using traditional marketing to meet their business objectives. Start-ups, Entrepreneurs, Business Owners who desire to make use of online media to improve their business goals and objectives.

    Digital Marketing Course in Chennai
    Digital Marketing Training in Chennai

    ReplyDelete
  33. Great work. Quite a useful post, I learned some new points here.I wish you luck as you continue to follow that passion.

    Mobile Apps Training

    ReplyDelete
  34. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ coimbatore airport taxi | Ooty travels

    ReplyDelete
  35. Your blog is awesome.You have clearly explained about it ...It's very useful for me to know about new things..Keep on blogging.

    React Training
    React Training in Chennai

    ReplyDelete
  36. Amazing Article ! I have bookmarked this article page as i received good information from this. All the best for the upcoming articles. I will be waiting for your new articles. Thank You ! Kindly Visit Us @ Coimbatore Travels | Ooty Travels | Coimbatore Airport Taxi | Coimbatore taxi | Coimbatore Taxi

    ReplyDelete
  37. Thanks for your great and helpful presentation I like your good service.I always appreciate your post.That is very interesting I love reading and I am always searching for informative information like this.Well written article Thank You for Sharing with Us pmp training Chennai | pmp training centers in Chennai | pmp training institutes in Chennai | pmp training and certification in Chennai | pmp training in velachery

    ReplyDelete
  38. Nice blog..! I really loved reading through this article. Thanks for sharing such an amazing post with us and keep blogging...Well written article Thank You for Sharing with Us project management courses in chennai |pmp training in chennai | pmp training institute in chennai | pmp training in chennai | pmp training class in chennai

    ReplyDelete
  39. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me
    Python training in bangalore
    Python course in pune
    Python training in bangalore

    ReplyDelete
  40. This is a nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.
    Best Devops online Training
    Online DevOps Certification Course - Gangboard

    ReplyDelete
  41. It seems you are so busy in last month. The detail you shared about your work and it is really impressive that's why i am waiting for your post because i get the new ideas over here and you really write so well.
    Data Science Course in Indira nagar
    Data Science Course in btm layout
    Python course in Kalyan nagar
    Data Science course in Indira nagar
    Data Science Course in Marathahalli
    Data Science Course in BTM Layout

    ReplyDelete
  42. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.
    Devops Training in bangalore
    Digital Marketing Training in bangalore
    Data Science Training in bangalore
    Java Training in bangalore

    ReplyDelete
  43. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Advanced AWS Training in Bangalore | Best Amazon Web Services Training Institute in Bangalore
    Advanced AWS Training Institute in Pune | Best Amazon Web Services Training Institute in Pune
    Advanced AWS Online Training Institute in india | Best Online AWS Certification Course in india
    AWS training in bangalore | Best aws training in bangalore

    ReplyDelete
  44. Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article. thank you for sharing such a great blog with us.
    rpa training in bangalore
    rpa training in chennai
    rpa training in pune
    best rpa training in bangalore

    ReplyDelete
  45. Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
    python training Course in chennai
    python training in Bangalore
    Python training institute in bangalore

    ReplyDelete
  46. positive emotions take hold of me better casino slot games when I thought about this casino

    ReplyDelete
  47. Thanks for sharing the good information and post more information. I need some facilitate to my website. please check once http://talentflames.com/
    training and placement company in Hyderabad

    ReplyDelete
  48. Thank you for giving the information and it is use full for me. training with placement company in Hyderabad

    ReplyDelete
  49. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    Android Course Training in Chennai | Best Android Training in Chennai
    Selenium Course Training in Chennai | Best Selenium Training in chennai
    Devops Course Training in Chennai | Best Devops Training in Chennai

    ReplyDelete
  50. Thank you for providing such an awesome article and it is a very useful blog for others to read.

    Oracle ICS Online Training

    ReplyDelete
  51. Thanks for providing a useful article containing valuable information. start learning the best online software courses.

    Workday Online Training

    ReplyDelete
  52. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels

    ReplyDelete
  53. Great blog. It help to clear the interview. Thanks for sharing such a good information. Keep posting blog related to interview cracking.
    Want to learn about data analytics then check with this data analytics courses in hyderabad it will help you to boost your career in data analytics.

    ReplyDelete
  54. Interesting information and attractive.This blog is really rocking... Yes, the post is very interesting and I really like it.I never seen articles like this. I meant it's so knowledgeable, informative, and good looking site. I appreciate your hard work. Good job.
    Kindly visit us @
    Sathya Online Shopping
    Online AC Price | Air Conditioner Online | AC Offers Online | AC Online Shopping
    Inverter AC | Best Inverter AC | Inverter Split AC
    Buy Split AC Online | Best Split AC | Split AC Online
    LED TV Sale | Buy LED TV Online | Smart LED TV | LED TV Price
    Laptop Price | Laptops for Sale | Buy Laptop | Buy Laptop Online
    Full HD TV Price | LED HD TV Price
    Buy Ultra HD TV | Buy Ultra HD TV Online
    Buy Mobile Online | Buy Smartphone Online in India

    ReplyDelete

  55. تمتلك شركة تنظيف مكيفات بالرياض افضل الطرق والمعدات في تنظيف الواحدات الداخلية والخاريجة للمكيفات توفر تنظيف المكيفات الاسبلت الفريون الكاست شركة غسيل مكيفات توفر خدمة تعبئة الفريون بسعر مميز شركة نظافة مكيفات تساعد علي رفع كفاءة التشغيل مرة اخري

    شركة تنظيف موكيت بالرياض
    نقدم خدماتنا مثل غسيل الموكيت والسجاد وغيرها فالهدف الاول هو راحة العملاء و اكتساب ثقتهم مهما تكلف الامر مع ضمان جودة الخدمات المقدمه و
    سرعة انجازها بكل سهوله و امان و على احدث و افضل الاساليب.

    شركة تنظيف واجهات زجاج وكيلادينج لديهم عمالة مدربة وادوات حديثة تريد خدمة ممتازة وبا اسعار مناسبة خدمة تنظيف عالية الجودة
    شركة تنظيف واجهات زجاج بالرياض

    افضل شركة لرش مبيدات بالرياض فنحن نقدم خدماتنا المتميزة في رش المبيدات الى المنازل والفلل والمحلات التجارية والفنادق المختلفه حيث تعتمد الشركة على مجموعه من المبيدات الآمنه والفعالة والموثوق فيها بإعتماد وزارة الصحة السعودية.

    لذلك تحرص شركتنا ارخص شركة مكافحة حشرات بالرياض كأفضل الشركات الموجودة فى الرياض على التخلص من جميع الأفات الشرسه مثلا الفئران وغيرها من القوارض التى من الممكن ان تكون سبب فى تدمير اغراض اى منزل او قد تسبب بعض الامراض اونقلها.

    ReplyDelete
  56. A befuddling web diary I visit this blog, it's incredibly grand. Strangely, in this present blog's substance made motivation behind fact and sensible. The substance of information is instructive
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  57. The article is very interesting and very understood to be read, may be useful for the people. I wanted to thank you for this great read!! I definitely enjoyed every little bit of it. I have to bookmarked to check out new stuff on your post. Thanks for sharing the information keep updating, looking forward for more posts..
    Kindly visit us @
    Madurai Travels
    Best Travels in Madurai
    Cabs in Madurai
    Tours and Travels in Madurai

    ReplyDelete
  58. Excellent Blog. I really want to admire the quality of this post. I like the way of your presentation of ideas, views and valuable content. No doubt you are doing great work. I’ll be waiting for your next post. Thanks .Keep it up!
    Kindly visit us @
    Luxury Packaging Box
    Wallet Box
    Perfume Box Manufacturer
    Candle Packaging Boxes
    Luxury Leather Box
    Luxury Clothes Box
    Luxury Cosmetics Box
    Shoe Box Manufacturer
    Luxury Watch Box

    ReplyDelete

  59. خدمة تقدمها شركة تسليك مجارى بالرياض
    تسليك مجاري بالضغط - تسليك مجاري المطبخ - وايت صرف صحي بالرياض - تسليك مجاري بالرياض - تسليك المجاري بالاسيد - تسليك المجاري بالملح - تسليك بالوعة المطبخ
    شركة تنظيف مكيفات بالرياض
    تمتلك افضل الطرق والمعدات في تنظيف الواحدات الداخلية والخارجية للمكيفات توفر تنظيف المكيفات الاسبلت الفريون الكاست شركة غسيل مكيفات توفر خدمة تعبئة الفريون بسعر مميز شركة نظافة مكيفات تساعد علي رفع كفاءة التشغيل مرة اخري

    شركة تنظيف مسابح بالرياض
    نقدم خدماتنا مثل غسيل المسابح وغيرها فالهدف الاول هو راحة العملاء و اكتساب ثقتهم مهما تكلف الامر مع ضمان جودة الخدمات المقدمه و
    سرعة انجازها بكل سهوله و امان و على احدث و افضل الاساليب.

    ReplyDelete
  60. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 

    Tableau online training

    ReplyDelete
  61. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.
    msbi online training

    ReplyDelete
  62. An overwhelming web journal I visit this blog, it's unfathomably amazing. Unusually, in this present blog's substance made inspiration driving truth and reasonable. The substance of data is enlightening
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training

    ReplyDelete
  63. Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this. 

    ReactJS Online Training

    ReplyDelete