Problem
Analysis
Forbidden triple for stack generability
© https://algs4.cs.princeton.edu/13stacks/
a permutation can be generated by a stack if and only if it has no forbidden triple (a, b, c) such that a < b < c with c first, a second, and b third (possibly with other intervening integers between c and a and between a and b).
Java
Greedy
1 | class Solution { |
Submission Detail
- 152 / 152 test cases passed.
- Runtime: 1 ms, faster than 93.97% of Java online submissions for Validate Stack Sequences.
- Memory Usage: 38.4 MB, less than 90.26% of Java online submissions for Validate Stack Sequences.
no stack
1 | class Solution { |
Submission Detail
- 152 / 152 test cases passed.
- Runtime: 0 ms, faster than 100.00% of Java online submissions for Validate Stack Sequences.
- Memory Usage: 38.9 MB, less than 18.73% of Java online submissions for Validate Stack Sequences.