You are given two coding problems.
Problem 1: Longest balanced subarray (0/1)
Given an integer array nums of length n where each element is either 0 or 1, return the maximum length of a contiguous subarray that contains an equal number of 0s and 1s.
Input: nums: int[] (each nums[i] ∈ {0,1})
Output: int = maximum length
Constraints (typical): 1 ≤ n ≤ 2e5
Problem 2: Longest increasing downward path in a binary tree (return the path)
Given the root of a binary tree where each node has an integer value, find a downward path (must follow parent → child pointers) such that for every adjacent pair on the path:
-
child.value > parent.value
(strictly increasing)
Return the entire path (e.g., as a list/array of node values in order from start to end) that has the maximum length.
If multiple longest paths exist, you may return any one of them.
Input: root: TreeNode with fields val, left, right
Output: int[] (or List<int>) representing the node values along the chosen maximum-length increasing path
Constraints (typical): up to 2e5 nodes.