PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving and data-structure manipulation, focusing on the sliding window technique for array subproblems and iterative breadth-first search for binary tree level-order traversal, with emphasis on time and space complexity reasoning.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Solve sliding window and tree BFS problems

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

1) Sliding window: Given an array of positive integers nums and an integer target, return the minimal length of a contiguous subarray whose sum is at least target; return 0 if no such subarray exists. Aim for O(n) time and O( 1) extra space using a sliding window. 2) Tree BFS: Given the root of a binary tree, return a list of lists of node values representing the tree’s level-order traversal from left to right (nodes within each level listed left to right). Provide an iterative BFS implementation and analyze time and space complexity.

Quick Answer: This question evaluates algorithmic problem-solving and data-structure manipulation, focusing on the sliding window technique for array subproblems and iterative breadth-first search for binary tree level-order traversal, with emphasis on time and space complexity reasoning.

Minimum Size Subarray Sum

Given an array of positive integers `nums` and an integer `target`, return the minimal length of a contiguous subarray whose sum is **at least** `target`. If there is no such subarray, return `0`. Aim for O(n) time and O(1) extra space using the sliding-window technique: expand the right edge to grow the window, and shrink from the left as long as the window sum still meets the target, tracking the smallest valid window length. **Example 1** ``` Input: nums = [2,3,1,2,4,3], target = 7 Output: 2 Explanation: The subarray [4,3] has the minimal length under the problem constraint. ``` **Example 2** ``` Input: nums = [1,1,1,1,1,1,1,1], target = 11 Output: 0 Explanation: The total sum is 8 < 11, so no subarray qualifies. ```

Constraints

  • 1 <= nums.length <= 10^5
  • 1 <= nums[i] <= 10^4
  • 1 <= target <= 10^9
  • All elements of nums are positive integers

Examples

Input: ([2,3,1,2,4,3], 7)

Expected Output: 2

Explanation: The subarray [4,3] sums to 7 (>= 7) with length 2, the shortest such window.

Input: ([1,4,4], 4)

Expected Output: 1

Explanation: A single element [4] already meets the target, so length 1.

Input: ([1,1,1,1,1,1,1,1], 11)

Expected Output: 0

Explanation: Total sum is 8 < 11; no subarray qualifies, so return 0.

Input: ([5], 5)

Expected Output: 1

Explanation: The single element equals the target, length 1.

Input: ([], 5)

Expected Output: 0

Explanation: Empty array — no subarray exists, return 0.

Input: ([1,2,3,4,5], 15)

Expected Output: 5

Explanation: Only the entire array sums to 15, so the minimal length is 5.

Input: ([1,2,3,4,5], 11)

Expected Output: 3

Explanation: [3,4,5] sums to 12 (>= 11) with length 3, shorter than any other valid window.

Hints

  1. A window of positive integers only grows when you extend the right edge and only shrinks when you advance the left edge — sums are monotonic, which is what makes the two-pointer sweep valid.
  2. Keep a running sum. Whenever it reaches `target`, record the current window length, then shrink from the left to look for an even smaller valid window before continuing to expand.
  3. Track the best length in a variable initialized to a sentinel (e.g. n+1). If it never improves, the answer is 0.

Binary Tree Level Order Traversal

Given the `root` of a binary tree, return a list of lists of node values representing the tree's **level-order traversal** from left to right (i.e., level by level, and within each level, nodes listed left to right). The tree is provided as a level-order array (LeetCode style), where `None`/`null` marks a missing child. Build the tree from this array, then return the level-order traversal using an **iterative BFS** with a queue. Process the queue one full level at a time so each inner list contains exactly the nodes at that depth. **Example 1** ``` Input: root = [3, 9, 20, null, null, 15, 7] Output: [[3], [9, 20], [15, 7]] ``` **Example 2** ``` Input: root = [1] Output: [[1]] ``` **Example 3** ``` Input: root = [] Output: [] ```

Constraints

  • The number of nodes is in the range [0, 2000]
  • -1000 <= Node.val <= 1000
  • The input array is a valid level-order encoding of a binary tree with None/null marking missing children

Examples

Input: ([3, 9, 20, None, None, 15, 7],)

Expected Output: [[3], [9, 20], [15, 7]]

Explanation: Root 3 at level 0; its children 9 and 20 at level 1; 20's children 15 and 7 at level 2.

Input: ([1],)

Expected Output: [[1]]

Explanation: Single node forms one level.

Input: ([],)

Expected Output: []

Explanation: Empty tree returns an empty list.

Input: ([1, 2, 3, 4, None, None, 5],)

Expected Output: [[1], [2, 3], [4, 5]]

Explanation: Level 0: [1]; level 1: [2,3]; level 2: 2's left child 4 and 3's right child 5.

Input: ([1, None, 2, None, 3],)

Expected Output: [[1], [2], [3]]

Explanation: A right-skewed chain 1 -> 2 -> 3 yields one node per level.

Input: ([5, -3, 8],)

Expected Output: [[5], [-3, 8]]

Explanation: Negative values are handled normally; root 5, children -3 and 8.

Hints

  1. Use a queue seeded with the root. The key to grouping by level is to capture the queue's size at the start of each iteration and process exactly that many nodes before moving on.
  2. For each node you dequeue, append its value to the current level's list and enqueue its non-null children (left before right) to be processed in the next round.
  3. Handle the empty-tree case up front: if the root is missing, return an empty list.
Last updated: Jun 26, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)