Open In App

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

Role: SDE1

Source: naukri.com



Online Round: 2 Coding Question with Time Complexity Analysis

  1. Similar to nearest K coordinates from Origin. (Heap)
  2. 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:

Round 2:

Round 3(Behavioural, taken by SDM III):

Round 4:

O/P: [1,3,6]
  • So, 1st Solution that I gave was normal dfs based that I try every path from root till every Leaf and in that method I take current_sum and one global_sum and update it accordingly.



  • 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;
      
    }
    
    
  • Time Complexity: O(more than N) I was not able to figure out but it is I guess O(N^2)
  • So, he told me to optimise it I told him that I will do something Post Order type Traversal and from left and right I will bring answer. But he told me that this will not work, So I was not able to find something better.
  • Conclusion: Be Confident in LP Questions, discuss Brute Force first.

    Verdict: Rejected


    Article Tags :