leetle

Daily challenge for 2026-01-12

377. Valid Stack Sequence Operations

Given a sequence of pushed elements pushed and a sequence of popped elements popped, determine if popped could have been the result of a sequence of push and pop operations on an initially empty stack using only the elements from pushed in order. The elements in pushed are distinct.

Example:
Input: pushed = [1,2,3,4,5], popped = [4,5,3,2,1]
Output: true

Input: pushed = [1,2,3,4,5], popped = [4,3,5,1,2]
Output: false

Run this challenge interactively in Python or JavaScript when the app loads.