# Amazon Interview Experience for SDE-1 | Off-Campus 2021

Role: SDE1

Source: naukri.com

**Online Round:** 2 Coding Question with Time Complexity Analysis

- Similar to nearest K coordinates from Origin. (Heap)
- Little bit of modification of 2-Sum, but I did in Brute Force way and it passed.

In the Last behavioural based MCQ Test.

After 5 days I got an email in which it mentioned that I will be having a quick connect with HR for Rounds Process.

**Round 1:**

- Quick Intro
- BST Iterator https://leetcode.com/problems/binary-search-tree-iterator/ (Medium)
- Basic Calculator https://leetcode.com/problems/basic-calculator/ (Hard)
- I Solved both but for last one my code was not 100% complete as we were running out of time but I gave the approach and final Time Complexity.

**Round 2:**

- Paint House https://www.lintcode.com/problem/515/?_from=[‘ladder’]&fromId=[’16’] (Premium on Leetcode, so attaching free Resource)
- BFS on Grid, The question was like you are given 2D Matrix with 0,1 and a starting coordinate from that you have to cover all 1’s and tell how much minimum time it will take to do that and if any 1 is left return -1.

**Round 3(Behavioural, taken by SDM III):**

- This Round was like brief Introduction, and that started with LP Questions
- A Deadline you missed.
- A Goal that you thought you will not be able to achieve but you did.
- A most Challenging Task you did.
- CS Fundamentals Questions, like difference between HTTP vs HTTPS, Thread vs Process, Memory Leak in Java, Classfull IP and its all Classes.
- After about a week I got an email that I am having my Last Round Next Week.

**Round 4:**

- A Small Introduction
- LP Questions
- 1 Coding Questions (Now for this I want to share that Interviewer itself was in doubt, the question was like you are given a Binary Tree with atmost 2 child and every child can have atmost 2 Parents, and you have to find a Maximum Path Sum from Root to Leaf)
- I asked what is the structure of that Node, So he said what you think. I wrote this:
- So he said Yes this is, (Now I was confused how come this can have links with Parent, maybe I am not able to get!)

## Java

`class` `Node ` ` ` `{ ` ` ` `int` `data; ` ` ` `Node left; ` ` ` `Node right ` ` ` `}` |

Sample Test Case:

1

/ \

2 3

/ \ / \

4 5 6

O/P: [1,3,6]

## Java

`int` `ans = ` `0` `; ` ` ` `List<Integer> finalAns; ` ` ` `private` `void` `dfs(TreeNode root, ` `int` `csum, List<Integer> ds) ` ` ` `{ ` ` ` `if` `(root==` `null` `) ` `return` `; ` ` ` `if` `(root.left==` `null` `&& root.right==` `null` `) ` ` ` `{ ` ` ` ` ` `if` `(csum > ans) ` ` ` ` ` `{ ` ` ` ` ` `ans = csum; ` ` ` ` ` `finalAns = ds; ` ` ` ` ` `} ` ` ` ` ` `return` `; ` ` ` `} ` ` ` `ds.add(root.val); ` ` ` `dfs(root.left,csum+root.val,ds); ` ` ` `dfs(root.right,csum+root.val,ds); ` ` ` `ds.remove(ds.size()-` `1` `) ` ` ` `} ` ` ` `pubic List<Integer> solve(TreeNode root) ` ` ` `{ ` ` ` `this` `.ans = ` `0` `; ` ` ` `this` `.finalAns = ` `new` `ArrayList<Integer>(); ` ` ` `this` `.dfs(root,` `0` `,` `new` `ArrayList<Integer>()); ` ` ` `return` `this` `.finalAns; ` ` ` `}` |

Conclusion: Be Confident in LP Questions, discuss Brute Force first.

**Verdict:** Rejected