Grokking the Coding Interview: Patterns for Coding Questions
Vote

0% completed

​

Solution: Next Greater Element

.....

.....

.....

Like the course? Get enrolled and start learning!
A

Anonymous

· 3 years ago

It would be nice to have such a comprehensive explanation + pseudo code for every pattern

A

Anonymous

· 3 years ago

  • Input: nums1 = [9,7,1], nums2 = [1,7,9,5,4,3]
  • Output: [-1,9,7]

In this example, we first take 9 and compare to every number to right of 9 in nums2. No number >9 so -1

Then 7. The 1st number to right of 7 (i.e only consider last 4 numbers in nums2) is 9

Now we consider 1. If we go by the same logic, we should only consider 5,4,3 in nums2. Why is the answer 7? Should it not be 5?

Thanks

M

Show 1 reply
A

Anonymous

· 3 years ago

There seems to be a mistake in the image. We are using monotonically decreasing stack.

Reading Progress

0%


Vote for new content