Pergunta de entrevista da empresa Goldman Sachs

Return the second-smallest element of a list.

Respostas da entrevista

Sigiloso

27 de out. de 2017

This can be done in following ways - Using collections: Collections.min(list); - Simple iteration: for (int i : array){ min = min < i ? min : i; }

Sigiloso

4 de dez. de 2017

Put in a max heap, pop the max, the top is now the second max.

Sigiloso

5 de dez. de 2017

#Python3 lst=[8,7,1,2,3,4,5] sorted(lst)[-2] #output is 7

Sigiloso

4 de jan. de 2018

pair a = (v[0] a.second) continue; if (*it < a.first) { a.second = a.first; a.first = *it; } else if (*it < a.second) { a.second = *it; } } return a.second;