Frage im Vorstellungsgespräch bei Goldman Sachs

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

Antwort im Vorstellungsgespräch

Anonym

22. Juli 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;