Interview Question

Software Development Engineer Intern Interview

Question regarding how to retrieve the second highest

  repeated number in array the second question was how to print the nodes of binary tree level wise
Tags:
technical
Answer

Interview Answer

2 Answers

0

I answered verbally the first one well. But i could not code(I panicked). The first interviewer was chilled out. He asked me regarding space complexities and stuff.

The second one I was able to write the solution on time but I could explain him the complexity issues. And I spoke some rubbish. I freaked out. I think that was the only reason i got rejection.

Interview Candidate on Feb 8, 2014
0

Retrieve the second highest repeated number in array
* Assuming no output if there aren't at least two pairs of repeated numbers
Create a vector of pairs of boolean and integer values
Using two variables, highest and second highest repeated values:
 - Initialize to some unreachable value (-1 or so)
For each number in array:
 - Check if the number is in the vector:
  - If not, add it to the vector and set the boolean to false
  - If it is and the boolean is false, set the boolean to true and:
   - Compare the value to the highest repeated value:
    - If it is higher, set the second highest to the old highest, and
       set the new highest to the number we've found
    - If it is lower, compare it to the second highest repeated value:
     - If it is higher, set the second highest to the number we've found
Upon completion of array iteration, second highest repeated value.
* This answer may not be perfect or optimal, but always give a fast solution
* and then improve upon it if it's found to be necessary.

Print the nodes of binary tree level wise
* Assuming pointers are accessible:
Have a helper function that gets called for all recursion that takes in depth
For all children (right or left) call the helper function with an incremented depth
 - If the depth matches, call a print function (or if POD, use printf or std::cout, etc)
 - If the depth exceeds, return

Anonymous on Jan 8, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.