Domanda di colloquio di Goldman Sachs

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

Risposta di colloquio

Anonimo

22 lug 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;