Find balanced subarray and increasing tree path

Quick Overview

This question evaluates array and tree algorithm skills, testing competency in identifying longest balanced subarrays in binary sequences and locating maximal strictly increasing downward paths in binary trees.

Find balanced subarray and increasing tree path

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

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 `0`s and `1`s**. **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.

Quick Answer: This question evaluates array and tree algorithm skills, testing competency in identifying longest balanced subarrays in binary sequences and locating maximal strictly increasing downward paths in binary trees.

|Home/Coding & Algorithms/Meta
Meta logo
Meta
Nov 2, 2025, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
5
0

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.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...