PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Apple

Solve interval, grid-fill, and heap tasks

Last updated: May 14, 2026

Quick Overview

These combined tasks evaluate algorithmic problem-solving and data-structure design skills, specifically interval aggregation and counting over large timestamp ranges, constructive grid-filling with 4-directional connectivity constraints, and multiset operations supporting efficient retrieval and removal of minima and maxima.

  • medium
  • Apple
  • Coding & Algorithms
  • Software Engineer

Solve interval, grid-fill, and heap tasks

Company: Apple

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are asked to solve the following algorithmic problems. ## Problem 1: Concurrent users from online intervals You are given `n` inclusive time intervals `intervals[i] = [start_i, end_i]`, each representing one user being online from `start_i` through `end_i` (integer timestamps). Return the online user count over time as a list of **disjoint** segments where the count is constant: `[t0, t1, c]` meaning for every integer time `t` with `t0 <= t <= t1`, exactly `c` users are online. ### Input - `intervals`: list of `n` pairs `[start, end]` with `start <= end` ### Output - `segments`: list of disjoint segments `[L, R, count]` sorted by time, covering exactly the union of times present in the input. ### Constraints (choose a reasonable approach) - `1 <= n <= 2e5` - Timestamps can be large (e.g., up to `1e9`), so avoid building an array over the raw time range. --- ## Problem 2: Fill a grid with vegetables so each type is connected You are given a grid with `R` rows and `C` columns. You are also given counts of vegetable types, e.g. `{'A': 4, 'B': 8, 'C': 3, ...}`, where the total count equals `R*C`. Fill the grid with these letters such that: - Every cell contains exactly one vegetable letter. - For each letter, all of its cells form a **single 4-directionally connected component** (up/down/left/right). ### Output Return any valid `R x C` grid, or report that it’s impossible. ### Follow-up How should your solution behave if some vegetable counts are `0`, or if `R*C = 0` (empty grid)? --- ## Problem 3: Support retrieving both min and max efficiently Design a data structure supporting these operations on a multiset of integers: - `insert(x)` - `getMin()` - `getMax()` - `popMin()` (remove and return current minimum) - `popMax()` (remove and return current maximum) ### Requirements - Target better than sorting the whole set on every operation. - Discuss time complexity. - Discuss when a counting/bucket approach could be better, and when it is not appropriate.

Quick Answer: These combined tasks evaluate algorithmic problem-solving and data-structure design skills, specifically interval aggregation and counting over large timestamp ranges, constructive grid-filling with 4-directional connectivity constraints, and multiset operations supporting efficient retrieval and removal of minima and maxima.

Related Interview Questions

  • Compute Earliest Bus Arrival - Apple (medium)
  • Find the Extra Edge - Apple (hard)
  • Rotate a Matrix In Place - Apple (medium)
  • Encode and Rebuild a Binary Tree - Apple (hard)
  • Wrap Matching Substrings in Bold Tags - Apple (medium)
Apple logo
Apple
Nov 27, 2025, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0

You are asked to solve the following algorithmic problems.

Problem 1: Concurrent users from online intervals

You are given n inclusive time intervals intervals[i] = [start_i, end_i], each representing one user being online from start_i through end_i (integer timestamps).

Return the online user count over time as a list of disjoint segments where the count is constant: [t0, t1, c] meaning for every integer time t with t0 <= t <= t1, exactly c users are online.

Input

  • intervals : list of n pairs [start, end] with start <= end

Output

  • segments : list of disjoint segments [L, R, count] sorted by time, covering exactly the union of times present in the input.

Constraints (choose a reasonable approach)

  • 1 <= n <= 2e5
  • Timestamps can be large (e.g., up to 1e9 ), so avoid building an array over the raw time range.

Problem 2: Fill a grid with vegetables so each type is connected

You are given a grid with R rows and C columns. You are also given counts of vegetable types, e.g. {'A': 4, 'B': 8, 'C': 3, ...}, where the total count equals R*C.

Fill the grid with these letters such that:

  • Every cell contains exactly one vegetable letter.
  • For each letter, all of its cells form a single 4-directionally connected component (up/down/left/right).

Output

Return any valid R x C grid, or report that it’s impossible.

Follow-up

How should your solution behave if some vegetable counts are 0, or if R*C = 0 (empty grid)?

Problem 3: Support retrieving both min and max efficiently

Design a data structure supporting these operations on a multiset of integers:

  • insert(x)
  • getMin()
  • getMax()
  • popMin() (remove and return current minimum)
  • popMax() (remove and return current maximum)

Requirements

  • Target better than sorting the whole set on every operation.
  • Discuss time complexity.
  • Discuss when a counting/bucket approach could be better, and when it is not appropriate.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Apple•More Software Engineer•Apple Software Engineer•Apple Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.