Daily challenge for 2026-05-30
515. Verify Stack Sequence Parity
Given an array of integers representing a sequence of push and pop operations, determine if the stack remains 'balanced' in terms of parity. For every positive integer in the array, push it onto the stack. For every zero in the array, pop the top element from the stack. If you encounter a zero and the stack is empty, the sequence is invalid. After processing all elements, return true if the sum of the elements remaining in the stack is even, and false if it is odd. An empty stack sum is considered 0 (even).
Example:Input: ops = [5, 3, 0, 2]Output: true
Explanation: Push 5, Push 3, Pop 3 (leaving 5), Push 2. Stack is [5, 2]. Sum is 7 (odd). Wait, the example logic: 5+2=7 is odd, so false. Let's use: [4, 2, 0, 6]. Push 4, Push 2, Pop 2, Push 6. Stack is [4, 6]. Sum is 10 (even). Output: true.