DEV Community

Discussion on: 456. 132 Pattern

Collapse
 
jiangwenqi profile image
Wenqi Jiang

Hey, Tony. Thank you for replying. I think the time complexity of monotonic stack is O(n). Because while loop is simply poping stack elements one by one and there can not be more than N elements pushed inside the stack ( every element pushed once ). So even though while loop is nested inside for loop it will not execute more that N times.