I am practicing monotonic stacks questions on leetcode. I find it difficult to figure out when to use a monotonically increasing stack vs monotonically decreasing stack. Looking for some tips from experts here. #software #engineering #algorithm
Use it for the daily (1/31) challenge question
You would use a monotonically increasing stack when you need to find the nearest smaller element to the right (for each element) in an array or sequence. Use cases for a monotonically decreasing stack are the obvious opposite: when you need to find the nearest smaller element to the left (for each element) in an array or sequence.
Is MSFT a monotonically increasing stock?