I was asked the below question in one of the face to face interview (virtual) round.
Implement an algorithm which does the following operations on a stream of integers.
- Insert and delete from start, end and middle of the stream at any given point.
- Get middle element from stream at any given point.
I explained an algorthim using doubly linked list with O(1) time complexity for all the operations but unfortunately got rejected with feedback shared by recruiter that I wasn't able to come up with a solution in the time complexity expected by interviewer (not sure if interviewers from amazon have deviced an algorithm which works better than O(1) time complexity). The interviewer wasn't even interested in listening to my solution, I was explaning all my thought process and from time to time had to ask him if he was listening or not and he'll just ask again what I was explaning.
Just a note to any amazon interviewer reading this post 'A candidate puts a lots of effort and time in prepraring for interviews, and sometime they get interview call after applying to 100+ job postings, so if you have already selected someone or made your mind to reject the candidate beforehand then please don't take the interviews or atleast don't give false feedback, let the feedback be genuine. For you it is just an interview but for a candidate it is much more than that'


