← back to unit
Medium
# stacks medium
The Matching Socks Pile
Socks come out of the dryer one at a time onto a pile. If the new sock matches the one on top — pair them and set them aside! 🧦
You get the socks in dryer order. Pile them with the pairing rule and print two things on one line: pairs <count> left <count>.
Example:
Input: socks = ["red", "blue", "blue", "red", "green"]
Output: pairs 2 left 1
red pushes, blue pushes, the second blue matches the top and pairs off, red now matches the new top red and pairs off, green pushes alone — 2 pairs made, 1 sock (green) left on the pile.
💡 need a hint?
stk-matching-socks.py🔒 given lines are locked — write your code in between
loading...