##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
3 7 apple banana cherry orange apple grape banana mango cherry kiwi
1
3 7 apple cherry banana orange apple grape banana mango cherry kiwi
We need apple, cherry, banana in this exact order. Find apple at position 1. Now look for cherry after position 1: found at position 5. Now look for banana after position 5: not found (banana is at position 3, before cherry). Answer is 0.
0
0 2 apple banana
The secret list is empty. An empty sequence is a subsequence of any sequence. Answer is 1.
1
A customer has a secret fruit list — a sequence of fruit names they want to buy. They also have a shopping cart — another sequence of fruit names.
Determine if the secret fruit list is a subsequence of the shopping cart. That is, all fruits in the secret list appear in the cart in the same relative order, but not necessarily consecutively.
If the secret list is empty, it is considered a subsequence of any cart. Output if the secret list is a subsequence of the cart, or otherwise.
We need to find apple, banana, cherry in order in the cart. Pointer (apple): scan cart, find apple at position 1. Pointer (banana): continue scanning, find banana at position 3. Pointer (cherry): continue scanning, find cherry at position 5. All matched, so answer is 1.