educative.io

Educative

Is solution two assuming the array is sorted?

Solution 2 assumes the array is sorted.

Hi Yumiko,
Yes, the solution 2 assumes that the array is sorted as written in Note at the start of solution 2.

The second solution works for sorted arrays only however, it’s given time complexity is show as O(nlogn) which suggests that we are given an unsorted array which is sorted in O(nlogn) and then solved in O(n).


Course: Coderust: Hacking the Coding Interview - Learn Interactively
Lesson: Find Pair With Given Sum in an Array - Coderust: Hacking the Coding Interview