Hardware interview practice
Forbid consecutive POP commands
Randomize a 20-command PUSH/POP sequence that never contains two adjacent POP commands.
Reviewed example
Work through one case
Input
randomize exactly 20 commands, each PUSH or POPExpected output
One valid result: [POP,PUSH,POP,PUSH,PUSH,POP,PUSH,POP,PUSH,PUSH,POP,PUSH,POP,PUSH,PUSH,POP,PUSH,POP,PUSH,POP]The first command may be POP, all entries use the two legal enum values, and no POP directly follows another POP.
What to cover
Requirements
- Allow either command at index 0.
- Check every later element against its predecessor.
- Do not procedurally repair the randomized sequence.
