Amazon||Interview experience| SDE INTERN(6 months)

Last Updated : 10 Oct, 2024

Amazon came to our campus.

ROUND 1- Online Assessment

There were two questions 1st was easy and 2nd was medium level.

ROUND 2-Interview

Amazon takes only one interview for SDE INTERN

Interviewer asked me to introduce myself and then told me to describe any project.

We are given a matrix(MXN) which is sorted row-wise and column-wise .Given a target element return the pair {row,col} is target exist in the matrix , else return {-1,-1}.

I gave three approaches for this

1st) Traverse the whole matrix and if we found that element then return respective row and column number else return {-1,-1}

T.C=O(MXN)

S.C=O(1)

2nd) Apply binary search on each row

T.C=O(MXlog(N))

S.C=O(1)

3rd) Take a pointer place it at 1st row and last column ,since the matrix is sorted row wise and column wise if( matrix[row][col] <targetE) row++;

else if(matrix[row][col]>targetE row col--;

else if matches then return that particuar row column

T.C=O(M+N)

S.C=O(1)

After giving 1st approach she asked me time and space complexity and asked to optimize them then after giving 2nd approach she asked time and space complexity and said that you are usking advantage of row wise sorted ,i want you to think of column wise sorted as well

After third approach she first said to dry drun ,like how approach is working and asked time and space complexity and said to code third approach.

After code she asked me to dry run 2 examples and to write time and space complexity of all approaches

Given a BST you have to replace each node's value with the sum of all node which are greater than it .

Traverse tree in inorder way and store inorder in vector and then traverse tree again (with any traversal) and find the element in inorder vector and take sum of all the elements after it and replace the nodes value with sum and do the same for rest.

T.C=O(N)+O(N*N) approx (for inorder traversal+any traversal * traversing vector )

S.C=O(N)(for storing inorder)+O(h)( auxillary stack space h=height of tree)

She said she dont want extra vector space that i was taking and told me to optimize

2nd approach) Apply inorder in opposite manner ,inorder is left root right ,reverse inorder will be right root left in this way we can access largest element first and we dont need to store in vector ,for largest element we have to replace it with zero since none element is greater than it. and we can take sum variable and add nodes value to it then we can replace nodes value with( sum-nodes value)

T.C=O(N) for inorder

S..C=O(h) where h is height of tree

After writing code she asked me to dry run for 2 test cases

Verdict: I didn't get selected

Comment