Skip to main content

Previous Greater / Smaller

Learn Previous Greater / Smaller (Stack, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Looking LEFT Instead of Right "Previous Greater/Smaller Element" asks the mirror question of Next Greater/Smaller: for each element, find the nearest one to its LEFT that is bigger (or smaller). Same monotonic stack technique, just scanned left to right while comparing against elements that came BEFORE - so a match is recorded immediately (no deferred pop-and-record needed).

More lessons in Stack