Top 15 Tricky Algorithm Interview Questions

How can you answer on tricky algorithmic questions when you have lack of time. The secret to success with this free-form question is to focus and practice. Never "wing it." What do you want the interviewer to remember most about you? List five strengths you have that are pertinent to this job: experiences, traits, skills, personality etc. Because if you prepare for the tough interview questions ahead of time, you'll likely do very well and actually enjoy the process. I have about 50 interviews with candidates at 3 companies that I used to work. Also I was in about 25 technical interviews around the world. The main idea of this article is make your brain think rapidly. Also increase creativity and grow yourself to broad-minded person.

Tricky Algorithm Interview Questions

"Like snowflakes, no two people are alike. Take some time to think about what sets you apart from others," advises Martin.

Here the list of top 15 tricky algorithm interview questions that you can be prepared to.

1. Given a rectangular (cuboidal for the puritans) cake with a rectangular piece removed (any size or orientation), how would you cut the remainder of the cake into two equal halves with one straight cut of a knife?

Join the centers of the original and the removed rectangle. It works for cuboids too! BTW, I have been getting many questions asking why a horizontal slice across the middle will not do. Please note the "any size or orientation" in the question! Don't get boxed in by the way you cut your birthday cake :) Think out of the box.

2. There are 3 baskets. one of them have apples, one has oranges only and the other has mixture of apples and oranges. The labels on their baskets always lie. (i.e. if the label says oranges, you are sure that it doesn't have oranges only, it could be a mixture) The task is to pick one basket and pick only one fruit from it and then correctly label all the three baskets.

HINT. There are only two combinations of distributions in which ALL the baskets have wrong labels. By picking a fruit from the one labeled MIXTURE, it is possible to tell what the other two baskets have.

3. Why is a manhole cover round?

HINT. The diagonal of a square hole is larger than the side of a cover! Alternate answers: 1. Round covers can be transported by one person, because they can be rolled on their edge. 2. A round cover doesn't need to be rotated to fit over a hole.

4. One train leaves Los Angeles at 15mph heading for New York. Another train leaves from New York at 20mph heading for Los Angeles on the same track. If a bird, flying at 25mph, leaves from Los Angeles at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled?

HINT. Think relative speed of the trains.

5. You have 5 jars of pills. Each pill weighs 10 gram, except for contaminated pills contained in one jar, where each pill weighs 9 gm. Given a scale, how could you tell which jar had the contaminated pills in just one measurement?

1. Mark the jars with numbers 1, 2, 3, 4, and 5.

2. Take 1 pill from jar 1, take 2 pills from jar 2, take 3 pills from jar 3, take 4 pills from jar 4 and take 5 pills from jar 5.

3. Put all of them on the scale at once and take the measurement.

4. Now, subtract the measurement from 150 ( 1*10 + 2*10 + 3*10 + 4*10 + 5*10)

5. The result will give you the jar number which has contaminated pill.

6. There are four dogs/ants/people at four corners of a square of unit distance. At the same instant all of them start running with unit speed towards the person on their clockwise direction and will always run towards that target. How long does it take for them to meet and where?

HINT. They will meet in the center and the distance covered by them is independent of the path they actually take (a spiral).

7. If you had an infinite supply of water and a 5 quart and 3 quart pail, how would you measure exactly 4 quarts?

We can pour water back and forth between the two jugs as follows:

OBSERVATIONS AND SUGGESTIONS: »»Many brain teasers have a math / CS root to them—this is one of them! Note that as long as the two jug sizes are relatively prime (i.e., have no common prime factors), you can find a pour sequence for any value between 1 and the sum of the jug sizes.

8. You have a bucket of jelly beans. Some are red, some are blue, and some green. With your eyes closed, pick out 2 of a like color. How many do you have to grab to be sure you have 2 of the same?

9. Which way should the key turn in a car door to unlock it?

10. If you could remove any of the 50 states, which state would it be and why?

11. How many cars are there in the USA?

12. You have 8 balls. One of them is defective and weighs less than others. You have a balance to measure balls against each other. In 2 weightings how do you find the defective one?

13. You've got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker?

14. You have two jars, 50 red marbles and 50 blue marbles. A jar will be picked at random, and then a marble will be picked from the jar. Placing all of the marbles in the jars, how can you maximize the chances of a red marble being picked?
What are the exact odds of getting a red marble using your scheme?

15. Imagine you are standing in front of a mirror, facing it. Raise your left hand. Raise your right hand. Look at your reflection. When you raise your left hand your reflection raises what appears to be his right hand. But when you tilt your head up, your reflection does too, and does not appear to tilt his/her head down. Why is it that the mirror appears to reverse left and right, but not up and down?

1) Study a data-structures and algorithms book. Why? Because it is the most likely to help you beef up on problem identification. Many interviewers are happy when you understand the broad class of question they're asking without explanation. For instance, if they ask you about coloring U.S. states in different colors, you get major bonus points if you recognize it as a graph-coloring problem, even if you don't actually remember exactly how graph-coloring works. And if you do remember how it works, then you can probably whip through the answer pretty quickly. So your best bet, interview-prep wise, is to practice the art of recognizing that certain problem classes are best solved with certain algorithms and data structures. My absolute favorite for this kind of interview preparation is Steven Skiena's The Algorithm Design Manual. More than any other book it helped me understand just how astonishingly commonplace (and important) graph problems are – they should be part of every working programmer's toolkit. The book also covers basic data structures and sorting algorithms, which is a nice bonus. But the gold mine is the second half of the book, which is a sort of encyclopedia of 1-pagers on zillions of useful problems and various ways to solve them, without too much detail. Almost every 1-pager has a simple picture, making it easy to remember. This is a great way to learn how to identify hundreds of problem types.

Other interviewers I know recommend Introduction to Algorithms. It's a true classic and an invaluable resource, but it will probably take you more than 2 weeks to get through it. But if you want to come into your interviews prepped, then consider deferring your application until you've made your way through that book.

2) Have a friend interview you. The friend should ask you a random interview question, and you should go write it on the board. You should keep going until it is complete, no matter how tired or lazy you feel. Do this as much as you can possibly tolerate. I didn't do these two types of preparation before my first interview, and I was absolutely shocked at how bad at whiteboard coding I had become since I had last interviewed seven years prior. It's hard! And I also had forgotten a bunch of algorithms and data structures that I used to know, or at least had heard of. As for short-term preparation, all you can really do is make sure you are as alert and warmed up as possible. Don't go in cold. Solve a few problems and read through your study books. Drink some coffee: it actually helps you think faster, believe it or not. Make sure you spend at least an hour practicing immediately before you walk into the interview. Treat it like a sports game or a music recital, or heck, an exam: if you go in warmed up you'll give your best performance.


Here the bonus for you, the list of TOP non technical or algorithmic, but still tricky questions by interview coach - Carole Martin

"Can you tell me about yourself?"
"Your answer to this question sets the tone for the rest of the interview.
"Practice your script until you feel confident.
Your script will help you stay on track, but don't memorize it -- you'll sound stiff.
Instead, aim for a natural and conversational tone".

"What are your long-term goals?"
This and other open-ended questions, like: "Where do you see yourself in five years?"
can throw you off balance.
The employer wants to check your self-awareness and communication skills here.
"If you're an organized type of person, answering this question may be a piece of cake.
If not, you'll need to give your answer some forethought."
The best answers will come from you thinking about what you want.
Most successful employers believe that a key success factor is
the ability to set and achieve goals.
So begin by setting short-term goals for yourself.
Right now your goal may be to get a job. But, what kind of job?
And, where do you go from there?
"No one can tell you exactly how to answer this question --
it will come from what is important to you. However, the more
focused and employer-centered you are about your goal,
the better your chances of steering the interview in the right direction".

"Why should we hire you?"
This is another broad question that can take you down the wrong road
unless you prepare thoroughly.
This is about selling yourself as a product. Why should the customer buy?
"Develop a sales statement. The more detail you give, the better.
This is not a time to talk about what you want.
It is a time to summarize your accomplishments and relate what makes you unique,"
Start by looking at the job description or posting.
What is the employer stressing as requirements of the job?
What will it take to get the job done? Make a list of those requirements.
Next, do a personal inventory. Think of two or three key qualities you have
that match what the employer is seeking.
Don't underestimate personal traits that make you unique -- your energy,
personality type, working style and people skills, for example.


Interview questions

Computer Architecture Questions on Technical Interview


DO NOT BE LATE FOR YOUR INTERVIEW and BE PREPARED! Expect some tough questions during the first interview as increasingly a lot of interviewers are using the first interview to weed out unsuitable candidates. Practice, practice, practice. What do you think about Tricky Algorithm Questions that I didn't answer yet?


Tricky Algorithm Interview Questions

Best articles: .NET Web frameworks, IOC pattern, IT articles, VS 2010 Tips.

Comments (6) -

  • Thanks for the post and continue writing.Please check this link for Algorithm and Computer Programming Languages Interview Question Answers
  • You have 8 balls. One of them is defective and weighs less than others. You have a balance to measure balls against each other. In 2 weightings how do you find the defective one?


    Rather doing 8 balls balance, just do 6, 3 balls on each balance side...
    if balance are found equal means remaining 2 balls, once of them is defective.If balance is unequal, unload the heavy side (put aside 3 balls from heavy side). Pick 2 ball from light balance that has 3 before put one aside and other one on other side of balance. If balance come equal means the put aside ball is the lighter one Smile else the lighter side of balance is the one Smile  

  • In question no.4, I believe the distance between those cities should be defined IMHO. It cannot be independent of the distance.
    • You are right. It cannot be measured otherwise.
  • Very easy questions.

Pingbacks and trackbacks (1)+

Comments are closed