File tree Expand file tree Collapse file tree 6 files changed +36
-2
lines changed
Expand file tree Collapse file tree 6 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 1+ const fn = ( arr ) => {
2+ let stack = [ ]
3+ let ans = 0
4+
5+ for ( const num of arr ) {
6+ while ( stack . length && stack [ stack . length - 1 ] < num ) {
7+ // TODO: logic
8+ stack . pop ( )
9+ }
10+
11+ stack . push ( num )
12+ }
13+
14+ return ans
15+ }
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ const fn = (arr) => {
33 let ans = 0
44
55 for ( const num of arr ) {
6- // for monotonic decreasing, flip > to <
76 while ( stack . length && stack [ stack . length - 1 ] > num ) {
87 // TODO: logic
98 stack . pop ( )
Original file line number Diff line number Diff line change 1+ def fn (arr ):
2+ stack = []
3+ ans = 0
4+
5+ for num in arr :
6+ while stack and stack [- 1 ] < num :
7+ # TODO: logic
8+ stack .pop ()
9+ stack .append (num )
10+
11+ return ans
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ def fn(arr):
33 ans = 0
44
55 for num in arr :
6- # for monotonic decreasing, flip > to <
76 while stack and stack [- 1 ] > num :
87 # TODO: logic
98 stack .pop ()
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ export default function SidebarLinks() {
2626 </ Accordion >
2727 < Accordion title = "Stack" >
2828 < LinkWithTooltip href = "#stack-monotonic-increasing" description = "monotonic increasing stack" />
29+ < LinkWithTooltip href = "#stack-monotonic-decreasing" description = "monotonic decreasing stack" />
2930 </ Accordion >
3031 < Accordion title = "Binary Tree" >
3132 < LinkWithTooltip href = "#tree-dfs-recursive" description = "DFS (recursive)" />
Original file line number Diff line number Diff line change @@ -3,7 +3,10 @@ import styles from '@sections/section.module.sass'
33import Tabs from '@components/Tabs'
44
55import MonotonicIncreasingStackPY from '@code/python/stack/monotonic_increasing.py?raw'
6+ import MonotonicDecreasingStackPY from '@code/python/stack/monotonic_decreasing.py?raw'
7+
68import MonotonicIncreasingStackJS from '@code/javascript/stack/monotonic_increasing.js?raw'
9+ import MonotonicDecreasingStackJS from '@code/javascript/stack/monotonic_decreasing.js?raw'
710
811
912export default function Stack ( ) {
@@ -16,6 +19,12 @@ export default function Stack() {
1619 < Tabs . Tab code = { MonotonicIncreasingStackJS } language = "javascript" />
1720 </ Tabs >
1821 </ section >
22+ < section id = "stack-monotonic-decreasing" >
23+ < Tabs title = "monotonic decreasing stack" >
24+ < Tabs . Tab code = { MonotonicDecreasingStackPY } language = "python" />
25+ < Tabs . Tab code = { MonotonicDecreasingStackJS } language = "javascript" />
26+ </ Tabs >
27+ </ section >
1928 </ div >
2029 )
2130}
You can’t perform that action at this time.
0 commit comments