$ ./guess_the_languageProblem Solving — fill the blank
Problem Solving — fill the blank · medium · #326

What goes in the blank?

# next greater element with a monotonic stack of indexes
for i in range(len(nums)):
    while stack and nums[stack[-1]] ____ nums[i]:
        res[stack.pop()] = nums[i]
    stack.append(i)

Answer: < (also accepted: <)

Every index still waiting on the stack whose value is smaller than nums[i] has just found its next greater element.
Play Problem Solving ▸