Amazon SDE Intern Interview Experience 6 Months
Summary
I recently had my Amazon SDE Intern final interview. I was presented with the 'Longest Substring Without Repeating Characters' problem, which I successfully solved by iteratively optimizing from a brute-force approach to an O(N) time and O(1) space sliding window solution, earning appreciation from the interviewer. I am currently awaiting the results.
Full Experience
At the start of my Amazon SDE Intern final interview, I introduced myself and shared my LeetCode and Codeforces ratings. The interviewer was impressed, acknowledging my consistent practice over the past year. He then stated that he wanted to assess my approach and thinking ability through a problem.
š§ Question Asked:
The problem I was presented with was "Longest Substring Without Repeating Characters". When I sought clarification, the interviewer specified that the string could contain a wide range of characters, including lowercase and uppercase letters, digits, special symbols, and spaces.
š” My Approaches:
Brute Force Approach:
I began by explaining the brute force method, which involves checking all possible substrings to find the one without repeating characters. I articulated that this would result in an O(n²) time complexity and O(1) space complexity.
Optimized Approach (O(n) Time, O(n) Space) Using Sliding Window:
Next, I described the sliding window technique, utilizing a hash map to keep track of the last seen index for each character. This brought the time complexity down to O(n) but maintained O(n) space.
Optimization to O(1) Space:
The interviewer then challenged me to achieve an O(1) space solution. I responded by suggesting that instead of a hash map, we could use a fixed-size array (like vector<int> arr(256)) to store the last indices, given the extended character set. He affirmed my suggestion.
Further Optimization ā Single Loop Solution (O(n)):
He pushed further, asking for a single-loop O(n) solution, pointing out that my current sliding window explanation still implied two loops (one for the right pointer 'j' and another for shrinking the window with the left pointer 'i'). After a moment of thought, I proposed storing the last occurrence of each character and intelligently moving the left pointer based on this information. With a small hint, I successfully implemented this final optimized solution and performed a detailed dry run, demonstrating its correctness with an example array. The interviewer was very pleased with my step-by-step logical progression.
I did make a minor error in the code (using s[i]-'A' instead of s[i]-'0' for character indexing), but the interviewer kindly corrected it.
š¬ Feedback from the Interviewer:
The interviewer complimented my confidence throughout the session. When I asked for feedback at the end, he humorously said he had already been giving it to me during the interview. He concluded by explaining his approach: "You know why I asked you only one question with three approaches? Because we want you to be production ready."
It's been three days since the interview, and I haven't received any updates. I'm curious about what kind of results I can anticipate, as this was my very first interview experience.
Interview Questions (1)
The problem was to find the longest substring without repeating characters within a given string. The interviewer clarified that the input string could include lowercase letters, uppercase letters, digits, special symbols, and spaces.