Pergunta da entrevista

Entrevista para C++ Software Developer - Scene Description API/Tools


Weta Digital

How do you find the biggest number ?


Respostas da entrevista

4 respostas


If you sorted the list of numbers why would you have to binary search to pick it out? It should either be the first or last one in the list depending on what you past as your comparator. And sorting is slow for this kind of question, since you will be removing and inserting items to figure out which one is the biggest. What they probably wanted to hear is if they didn't want it optimized was a single for-loop with a comparator. This should get done in O(n). If they wanted it optimized, a divide and conquer strategy will find the answer in lesser number of comparisons. If you're looking for a STD solution it's "std::minmax_element(first, last);"

Duan em


You are so right ! Now I can't remember whether the question was to find a target number, or the biggest. If the latter, then for sure that would be the killer reason I failed the interview! Thanks very much for the solution.

Nat em


Sorting + Binary search = O(n log n) + O(log n) Linear search = O(n) ???

Interview Candidate is wrong em


Sort and use binary search.

Sigiloso em

Adicionar respostas ou comentários

Para comentar sobre isso, entre na conta ou cadastre-se.