Solved LeetCode program · 374 of 1,000
#0503 · Next Greater Element II
Original English source
Keep a shared numbers holding 1, 2, and 1. Keep a shared width of 0. Keep a shared answer of 0. Keep a shared last of 2. Set width to last plus 1.
To seek from step (a whole number) with spot (a whole number). If step is at least width, set answer to -1, return. The other is spot plus step. If other is more than last, set other to other minus width. If item other of numbers is more than item spot of numbers, set answer to item other of numbers, return. Seek from step plus 1 with spot.
For every spot from 0 to last.
Set answer to -1. Seek from 1 with spot. Show answer.
Expected stdout
2 -1 2