InternDoor

Three on the rise

Mediumarrays · greedy

Reported in interviews at (where)

Does the list nums hold three positions i < j < k with nums[i] < nums[j] < nums[k]? The three need not sit next to each other.

Return true if they exist and false if not, in one pass and without an extra list.

Example 1
Input
nums = [5,1,4,2,6]
Output
true

1, 4, 6 at positions 1, 2 and 4.

Example 2
Input
nums = [9,7,7,3]
Output
false

The list never rises.

Example 3
Input
nums = [2,9,1,3]
Output
false

2 < 9 and 1 < 3, but no three positions rise in order.

Limits

  • 1 <= nums.length <= 100000
  • -2^31 <= nums[i] <= 2^31 - 1

Hints

Hint 1

Keep the smallest value seen, and the smallest value that has something smaller before it.

Hint 2

A number bigger than both finishes a triple.

Where this was reported

Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.

Run your code to check it on the examples. Submit runs every hidden test.

Ready for the real one?

Engineering internships and entry-level jobs in India, newest first.