Goldman Sachs interview question

Find depth of the binary tree? How would you insert an element in sorted array

Interview Answer

Anonymous

22 Jul 2019

Insert element in a sorted array: Make sure the array capacity is at least n+1. If the array capacity is not given, make a new array with length n+1. for(int i = 0; (i >= 0 && arr[i] > key); i--){ arr[i+1] = arr[i]; } arr[i+1] = key;