I was just asked in a tech interview to write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C.

That's it. That is all the information I was given.

I asked the interviewer what the goal was but apparently there wasn't one, just "traverse" the "object".

I don't know about anyone else, but this seems like a silly question to me. I asked again, "am I searching for a value?". Nope. Just "traverse" it.

Why would I ever want to endlessly loop through this "object"?? To melt my processor maybe??

The answer according to the interviewer was that I should have written a recursive function.

OK, so why not simply ask me to write a recursive function? And who would write a recursive function that never ends?

My question:

Is this a valid question to the rest of you and, if so, can you provide a hint as to what I might be missing? Perhaps I am thinking too hard about solving real world problems. I have been successfully coding for a long time but this tech interview process makes me feel like I don't know anything.

  • 199
    The only correct answer here is "I don't understand the question."
    – user16764
    Apr 12, 2012 at 21:17
  • 16
    Well, if they really didn't say what A,B, and C are (like - they are objects) and they put object in quotes, they seem to have there own unique terminology. If they asked how to traverse an object graph where object A references object B which references object C which references object A it would have been intelligible, but why it has to be recursive I don't know. It needn't be infinite if you maintain a list of already visited objects, by the way. But yes, I would be concerned about working for a company using that test - they seem confused.
    – psr
    Apr 12, 2012 at 21:18
  • 77
    The question as described is nonsensical, and so is the answer. Either you're misremembering what they asked, or the person doing the asking is an idiot and you're probably better off not working with him. Apr 12, 2012 at 21:18
  • 26
    Why do dev interviews have to be painful? Can't we all just sit down and look at each other's code and discuss? Devs will know where other devs are at by doing this and it won't take 6 hours. Code tests are the worst. I don't mind admitting that I suck at delivering optimum solutions while 3 devs I've never met watch me as I type. Apr 12, 2012 at 23:10
  • 19
    I had to check your profile to see if you lived in the same area as me because I worked for a short time at a job where a fellow interviewing me asked, "Are you detail-oriented?" To which I replied, "Can you be more specific?" And his reply, "I can't explain it, but I know a detail-oriented person when I see their work." Love ambiguity. Apr 13, 2012 at 5:42

13 Answers 13


It's a baffling, invalid interview question. The interviewer couldn't clearly articulate what it was that he/she was looking for and expected you to read his/her mind instead of responding meaningfully to your appropriate attempts to clarify the statement of the problem. Consider yourself lucky you didn't get the job.

The meaning of the verb "traverse" operating on a generic "object" is ambiguous, in my opinion. Start substituting a variety of different nouns for the word object and it quickly becomes obvious that traversal of an object is only meaningful for a small subset of the universe of things that are objects.

It makes sense to "traverse" the nodes of a "binary tree". It doesn't make sense to "traverse" a "clown". Yet, an object can just as easily represent a "clown" as it can represent a "binary tree".

  • 10
    I've recently gotten into the practice of replacing nouns in silly questions with the word "clown" +1 sir!
    – rupjones
    Apr 12, 2012 at 21:57
  • 110
    "Clown traversal" - what a great Meme for "stupid technical question". Pass it on!
    – radarbob
    Apr 12, 2012 at 22:50
  • 8
    Hmm, I can traverse var clown = { hat:"with flower", hair:"bright red", nose:"red ball", mouth:"Red mouth framed in white",...} ;)
    – mplungjan
    Apr 13, 2012 at 7:29
  • 38
    My entire area of theoretical CS research involves iterative clown traversal, you insensitive clod!
    – user11946
    Apr 13, 2012 at 15:54
  • 6
    @JackManey: Everyone knows that clowns must be traversed recursively. Apr 15, 2012 at 3:09

I can see three possibilities here.

  1. She was completely incompetent. Not much more to say on that one.
  2. She was deliberately making it ambiguous, to see how well you'd do at asking questions to figure out what you were supposed to do, and what she was really after.
  3. For whatever reason, she'd decided she didn't want you hired, so she asked a question that was unanswerable as given. When she was asked about your skills, she'd skip over that part and say something like: "I asked him about how to traverse a three-node graph, and he was completely stumped -- didn't have even a clue of how to start. Obviously he's grossly incompetent! We shouldn't even consider hiring him."
  • 7
    "I asked him about how to traverse a three-node graph, ..." If the OP post i correct, there no mention of a graph or node. just "objects". This is a form of "false testimony". If she writes something like this can be prosecuted! Apr 13, 2012 at 6:52
  • 9
    Do you usually use female pronouns when the gender of the person is not mentioned? Apr 13, 2012 at 10:01
  • 8
    @EmilioGaravaglia: First of all, it might never be written. Second, even assuming it gets written down, you'll undoubtedly never get access to it, just a "we regret to inform you..." letter. Third, unless you have a recording of the interview, how would yo prove the interviewer wasn't telling the truth? Bottom line: in theory you should be right -- but in reality, there's virtually no chance. Apr 13, 2012 at 13:31
  • 12
    @Chan-HoSuh: The OP mentions the gender in one of his comments. Apr 13, 2012 at 13:31
  • 4
    @JerryCoffin My apologies then. Apr 13, 2012 at 16:43

This is just a wild guess, but assuming the interviewer is talking about pointer references (and it's a trick question), the answer is: there's nothing to traverse, because all of the references point to the same object.

A recursive function? That's for traversing a tree. I see nothing in the original question that would imply that he's talking about a tree.

  • 28
    Move on. There are better companies to work for.
    – shufler
    Apr 12, 2012 at 21:18
  • 7
    Nah. It's a lost cause. If the interviewer thought he was wrong, he wouldn't have asked the question in the first place. I was once asked to write a sample in any language I wanted to; the person interviewing me assumed that pseudocode was a valid choice. Apr 12, 2012 at 21:19
  • 8
    @Robert Harvey: What's wrong with pseudocode?
    – James
    Apr 12, 2012 at 21:37
  • 6
    @Robert Harvey: To be fair all most people want is to figure out how you solve the problem not to find out if you've learned off the syntax of any particular language. It's quite common for algorithms to be specified in pseudocode.
    – James
    Apr 12, 2012 at 21:47
  • 8
    What's the difference between pseudocode and Python? :) Apr 13, 2012 at 5:30

While I cannot speak for this specific interviewer, I've seen similar questions in a front-end developer position interview, so the language I'll use in this example will be JavaScript.


var A = {
    key1: 'value1',
    key2: 2,
    key3: {
        innerkey1: 'value3'

A typical wrong response may "traverse" the first level only and print/compare:

[Object object]

So while coding a recursive example that would traverse all levels, I would mention things like:

  • Circular reference handling
  • How to handle arrays (should they be recursively traversed too?)
  • Should functions be evaluated and their return value processed?
  • For JavaScript: should the prototype match and should inherited properties also be compared?

So the "solution" that I'm guessing the interviewer was going for was to get a conversation started on a seemingly-simple question that has many advanced topics - recursiveness, pointers/references, expectations, etc.

  • 5
    That makes sense that way you put it, WSKid. Unfortunately, none of that context was offered. Apr 12, 2012 at 21:28
  • 3
    True, this is really grasping at straws. They should have presented a use case, or an example 3 objects, or something to give a lead in to the actual problem.
    – WSkid
    Apr 12, 2012 at 22:37
  • 1
    I was thinking the same, only for python object attributes. Knowing which question they expected an answer in would have been hugely helpful, but that could be expected by the context of the position, ie python dev, c# dev, javascript dev, php dev, etc
    – Ken
    Apr 13, 2012 at 1:34
  • 2
    +1 for finding a context where the question makes some sense! Jun 17, 2013 at 18:06

Some interviewers specifically try to ask questions to see if the candidate is smart and honest enough to give one of these two answers:

I don't know.

or maybe:

I can't answer that as stated.

They don't want a candidate who will accept pure BS as a spec, and waste their employer's time and pay trying to implement it.

  • 6
    Our entire lives we are conditioned, in such a scenario as this interview, to be able to provide an answer to a question. If saying "I don't know" (which I did, by the way) was acceptable, then I should have been told that before hand as well. An attempt in good faith to answer an interview question is not necessarily tantamount to how one would treat an inadequate spec or set of requirements. And I think this is the whole point, these interviews have veered off course and are missing the point in many cases. Apr 13, 2012 at 7:41
  • Such a good answer. However, don't forget that it takes a lot of experience to be able to say this. Personally, I can say that experience with interviews is a vital part of the job. @MatthewPatrickCashatt if the interviewer will not accept "I don't know", then not much more to dicuss IMO.
    – arin
    Apr 13, 2012 at 16:12
  • 2
    Trick questions are either trolling or abject incompetence. Either way if an interviewer asks trick questions you don't want to work there.
    – Ben Brocka
    Apr 13, 2012 at 21:26

It seems to me that this is a (poorly articulated) question regarding a circular linked list. I would have likely asked if that is what was meant (because the answer would be certainly different than another above which is to say they are all references to the same object).

If this was a linked list question, then you (in this case) have a singly linked list, where the end node points to the other end (although if it was worded as you say - then it may be doubly linked if A points to B and C - but clarification on the interviewer's part would help this).

A -> B -> C -> A

Also (and this happens all the time), the interviewer may have read this question, thought it was a 'good' question, but didn't actually know the answer themselves (or even what it meant).

  • 1
    Thanks Maich--I think that your final point is the most likely. Apr 13, 2012 at 2:35

Part of the challenge here is to get more detail by asking specific questions to get out that there is a tree structure and what are the components involved in doing a traversal. There may have been the assumption that there aren't many other data structures that one traverses besides trees but that is a bit of a leap to my mind.

  • 1
    Thanks JB King. It is good a good reminder to ask questions. In this particular case, I did. In fact, I even asked if it was a tree and the answer was no! But your point is well taken that it is my responsibility to distill as much information as possible by asking questions. Apr 12, 2012 at 21:47

They may want to try to figure out how you deal with strange problems. But in this case, it has nothing to do with a "tech interview". It looks more like a psychological interview.

  • 5
    I'd love to see an example of one of their tech specs for a software project.
    – Chuck D
    Apr 13, 2012 at 1:35
  • If the interview is for a systema analyst or a similar position, this is entirely apt: your job is to help customers clarify their questions, rather than to answer them. Apr 13, 2012 at 13:26
  • 1
    @reinierpost--It wasn't. Apr 13, 2012 at 15:06

Write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C.

It seems like most people assume that A, B, and C are pointers, but they could just as easily be clowns, too. (Or members of the clown class.) Or they could be clown names. (Or class names. Or subclasses of the clown class.)

I would have turned the tables and asked if this is how they typically prepare development specifications, and then tell them how I could help them with the requirements specification stage of development. Poor communication of expectations leads to poor work product. Either they would get it or they wouldn't, If they didn't get it, I would walk away.


While the question was poorly worded and the interviewer was clearly unhelpful in providing any direction, I have a slightly different take on what was being asked.

I think interviewer was looking for a solution that traversed the object structure using some type of reflection. The information that the three objects were equal should have prompted a conversation of object identity comparison (A == B means the objects are really the same object in memory), or object equality comparison (A == B means the values of the objects are the same).

The fact that the interviewer said that the answer was a "recursive" function, probably indicated that a discussion of deep versus shallow copying and comparison was expected.


Coming very late to this party, but I think the interviewer incorrectly asked this question:

Write an algorithm to traverse an array and determine that A is equal to B and B is equal to C and A is equal to C, in that order.

Then the correct answer would be a recursive algorithm.


I was just asked in a tech interview to write an algorithm to traverse an "object" (notice the quotes) where A is equal to B and B is equal to C and A is equal to C.

The object in question is made up of the parts A,B and C, and it forms a triangle. The person is simply asking if the object (a collection) contains all equal parts.

The interviewer wants to know if presented with parts A, B and C can you tell if they are all equal without getting stuck in an infinite loop. This question is stupidly simply to understand and still they managed to f*** it up in asking it.

They are all equal when A == B && B == C && A == C, but that can be simplified to just A == B && A == C.

The simplicity of the question resulted in confusion, and it really is worded badly.

The correct wording should have been.

Write an algorithm to check the parts of a collection to see if they are all equal to each other. Care must be given not to get stuck in an infinite loop. For example; if parts A is equal to B and B is equal to C and A is equal to C could cause problems.

The answer according to the interviewer was that I should have written a recursive function.

Yes, you can answer the question are all my parts equal using recursive functions. No, this is not an efficient solution.

EDIT: After some thought. No it's not possible to check a collection contains all equal parts using a recursive function.

The most efficient solution is as follows.

function are_all_equal(parts)
   for(int i=1; i < parts.length; i++)
       if parts[i] is not same as parts[0]:
           return false;
   return true;

print are_all_equal(parts) ? "yes" : "no";

This problem does occur in programming, and asking someone to write an algorithm to test a collection is perfectly normal. Depending upon the programming language this problem can often be solved with just one line of code.

Wording as they did, and expecting the wrong answer is not normal. Since this question was ask a year ago. I truly hope you ended up working somewhere else. I'd be interested in hearing from the original post how things turn out for him/her.

  • 2
    Things turned out great--ran as fast as I could from that company and have been happy ever since. Jun 17, 2013 at 22:41

Was this a Java interview question, if so, may be he wanted to test your skills with overriding "hashcode" and "equals".

You would have to override these two methods and use the overridden equals method to stop the recursion when you compare A with A.

Without overriding, your comparison for "object" A to B, A to C and A to A will all result true but after overriding, only when object A compared to object A will return true where as other comparisons will return false.

Not the answer you're looking for? Browse other questions tagged or ask your own question.