# Amazon Interview Experience for SDE-2

Round 1: DS Algo round

The interviewer asked me about briefly my current experience, but that didnt seem like the goal of the interview round.

Then he started with ds algo questions. Below are the specific questions he asked:

1. Given a string and “ab”, determine if the string can be generated by “ab”. If it can form, then return true or else return false. Initial assumption is that the given input string will only contain characters ‘a’ and ‘b’.
• Examples:
• “aaabbb” – true
• “caabb” – false
• “abababab” – true
• “aaabbbb” – false
• Basically the rule is, for each ‘a’ in the given string, there should be a corresponding ‘b’ after that ‘a’.
• My solution:
• Have a counter set to 0
• traverse through the string, for each character, if it is ‘a’, increment the counter, if it is ‘b’, decrement the counter.
• At any point in array, if the counter is less than 0, then return false.
• Once the array traversal is over, then if the counter is 0, then return true else return false.
• He then asked to consider the input array having other characters than ‘a’ and ‘b’ as well.
• Asked to write production level code to solve this problem. But I had to only write the method.
2. Reverse every k element set of singly linked list.
• Examples:
• list: 1 2 3 4 5 6 7 8 9, k:3 — output: 7 8 9 4 5 6 1 2 3
• list: a b c d e f g h i j k l, k : 4 — output: i j k l e f g h a b c d

Then one more question: What would you do if you have 5 tasks, and a deadline where you can only perform 3 tasks. What would you do?

Round 2: DS Algo (again)

This round also was about ds and algo, but before going to that, he asked a couple of work related questions like:

• What is the daily work that you have to do, specific to your role and responsibilities

Then he moved to ds algo questions:

1. Consider the number keypad of old mobiles. number 2 will be associated with a, b, c. number 3 is associated with d, e, f. number 4 is associated with g, h, i…. so on and number 9 is associated with w, x, y, z. Now, the input to your method is  a number. You have to print all the strings that can be formed by that number considering the association described.
• Examples:
• Input is 23 — output would be { ad, ae, af, bd, be, bf, cd, ce, cf}
• Input is 259 — output would be { agw, agx, agy, agz, ahw, ahx, ahy, ahz, aiw, aix, aiy, aiz, bgw, bgx, bgy, bgz, bhw……. ciw, cix, ciy, ciz}
2. Zig zag printing of a binary tree of node type as string, but when you are printing right to left, you need to print string in reverse.
• Example:

“abc”

|             \

“def”      “ghi”

|      \         |       \

“jk”  “lm” “no”  “pq”

The output would be:

abc

ihgfed

jklmnopq

Round 3:

I was rejected in the second round. I do not know the reason because I had given right answer to all the questions, and wrote working code on paper as well. Anyways, “kuch koshishen taiyaari ke liye hoti hain” right? 🙂 All the best my fellow geeks!!

Write your Interview Experience or mail it to contribute@geeksforgeeks.org

My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

2

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.