# Amazon Interview Experience for SDE1 | On Campus – Aug 2021

**Round 1:**

This was an online test. It consists of 5 sections.

**Debugging**: We have to select a language before attempting this section. There were 7 questions. This section was easy and questions were mostly on sorting, removing an element from an array, etc.**Coding:**There were two questions. One was easy (https://www.geeksforgeeks.org/given-an-array-a-and-a-number-x-check-for-pair-in-a-with-sum-as-x/) and the other one was https://leetcode.com/discuss/interview-question/699973/goldman-sachs-oa-turnstile.**Aptitude****Behavioral****Feedback**

**Round 2:**

The interviewer was SDE2. He introduced himself and asked me to introduce myself. He then jumped into coding questions.

- This question was based on topological sorting. Given several courses in a college. Each course may have a prerequisite course that you have to complete in any of the previous semesters if you want to complete the current course in the current semester. The courses which have prerequisites completed or courses that have no prerequisites can be completed in one semester. Return the minimum number of semesters to complete all courses. Discussed the Breadth-First Search approach and coded the same. He then asked about the time complexity ( time and space complexities are very important, learn to calculate them and tradeoffs between them)
- https://www.geeksforgeeks.org/rearrange-characters-string-no-two-adjacent/

Haven’t solved this one before. Discussed with him the intuition that the maximum frequency characters are the most important here and we should arrange them apart first. I kept on discussing and finally got the idea to solve it by using heap (take top 2 frequency characters and arrange them side by side. Decrease their frequency and insert them again into the heap). He asked me to code it out and then asked me the time complexity. I said O(N log N) as we are using the heap (It was a blunder). But he asked me to think again. After some time he gave a hint that we can have a maximum of 26 characters in heap. Then I told that the time complexity is O(N) (for getting the frequency of characters) since heap operations are of O(1) time.

Then he asked me whether I had any questions for him. I asked him how would be the work for an SDE1 and workload in the company.

**Round 3:**

I introduced myself to the interviewer and then he jumped into the questions.

- https://www.geeksforgeeks.org/decode-string-recursively-encoded-count-followed-substring/ discussed the stack approach. He then asked me to code and a dry run for a given test case. He asked me the time complexity. I told it is O(N* maximum k value in the string).
- This was a hard question. There are N cities, and M roads (bidirectional) connecting them. Given start city, end city, and an initial tank value (V). Traversing each edge would cost one unit of tank value. However, few cities are called fuel cities, we can full the tank to its initial value when we reach them. Return a boolean representing whether we can reach the end city from the target city or not. Haven’t solved this kind of problem before, I asked him to give me 2 minutes to think and come with an approach. After that, I discussed the Breadth-First Search approach where I would store the city and tank value in a queue and traverse in a conventional Breadth-First Search manner by maintaining a 2D visited array. He then asked me to code. After that, he showed me a test case where this approach would be failing. Then I discussed with him and told him that we can revisit a city if we have a tank value more than the last time. He asked to modify the code.

**Round 4:**

The interviewer was a senior engineer. He was very friendly and he told me this round will consist of coding and behavioral questions.

He gave me a string which is basically an HTML document and asked me to return a boolean value representing whether the given HTML document is valid or not. I then came up with a valid parenthesis approach ( opening an HTML tag should have a respective closing HTML tag adjacent to it). He then showed a test case where there is a body tag embedded within the head tag and told that even this should return false. Then I asked for some time to think. After that, I told that I construct a tree or a graph that represents the proper DOM structure that is valid. Then I told that whenever a encounter a tag I will check that its parent in the given document is valid or not by looking up the adjacent nodes or parent ( in case of tree). He was impressed with that and asked to code it out. I couldn’t complete the code within time. He then asked some questions on my projects and asked what was the most difficult thing I have encountered while doing my project, how did I handle it. And he asked what would I do when I got stuck in a project, whether I ask my mentors/seniors or do it myself.

At last, he asked me whether I had any questions for him. I asked the same questions ðŸ™‚

( show them how much you are interested in joining the company whenever you got this chance)

**I was offered a 6-month internship and FTE at the end of the** **hiring process.**

Hey geek! It’s time to become a success story instead of reading them. Check out our most renowned **DSA Self Paced Course**, now at a student-friendly price and become industry ready. And if you are looking for a more complete interview preparation resource, check out **Complete Interview Preparation Course**** **that will prepare you for the SDE role of your dreams!

Feeling prepared enough for your interview? Test your skills with our **Test Series** that will help you prepare for top companies like **Amazon, Microsoft, TCS, Wipro, Google** and many more!