# stacks medium

The Sandwich Fix

Disaster: one wrong ingredient in the middle of the sandwich! Unstack down to it, flick it out, restack the rest. 🥪

You get the layers bottom to top and the wrong ingredient (exactly one). Every layer lifted off counts as a move, removing the wrong one is a move, and putting each lifted layer back is a move. Print the total moves.

Example:

Input: layers = ["bread", "ham", "pickle", "cheese", "bread"], wrong = "pickle" Output: 5

2 layers (cheese, bread) sit above pickle. Each moves off and back on (2 × 2 = 4 moves), plus removing pickle itself (1 move) makes 5 total.

💡 need a hint?

stk-sandwich-fix.py🔒 given lines are locked — write your code in between
loading...