The TransCompilator

Solved LeetCode program · 767 of 1,000

#1003 · Check If Word Is Valid After Substitutions

Medium String chunk-16.md

Original English source

The source is "aabcbc". The stack is an empty list of text.
For every spot from 0 to the last position of source.
The symbol is the slice of source from spot to spot plus 1. Place symbol into stack. The size is the number of items in stack.
If size is at least 3.
The bottom is item (size minus 3) of stack. The middle is item (size minus 2) of stack. The top is item (size minus 1) of stack. The formed is 0. If bottom matches "a", add 1 to formed. If middle matches "b", add 1 to formed. If top matches "c", add 1 to formed. If formed is 3, remove the last item from stack, remove the last item from stack, remove the last item from stack.

The remaining is the number of items in stack. If remaining is 0, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true