PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This set of problems evaluates algorithm design and problem-solving skills across array manipulation, range-update techniques, load-balancing and partitioning strategies, and combinatorial packing, testing competencies in complexity analysis, data-structure use, and optimization under constraints.

  • Pinterest
  • Coding & Algorithms
  • Machine Learning Engineer

Solve five hard algorithm problems

Company: Pinterest

Role: Machine Learning Engineer

Category: Coding & Algorithms

Interview Round: Onsite

The coding rounds covered the following algorithmic problems: 1. **Transform one array into another using range `+1/-1` operations** You are given two integer arrays `nums` and `target` of equal length `n`. In one operation, choose a contiguous subarray `nums[l..r]` and either add `1` to every element in that subarray or subtract `1` from every element in that subarray. Return the minimum number of operations needed to transform `nums` into `target`. 2. **Build a target array from zeros using range increments** Start with an array of `n` zeros. In one operation, choose a contiguous subarray and add `1` to every element in it. Given a target array of non-negative integers, return the minimum number of operations required to construct the target array. 3. **Minimize the maximum load when assigning jobs** You are given an array `jobs`, where `jobs[i]` is the time required for job `i`, and an integer `k` for the number of workers. Assign each job to exactly one worker. The load of a worker is the sum of job times assigned to that worker. Return the minimum possible value of the maximum worker load. 4. **Place boxes into a warehouse from one side** You are given an array `boxes` of box heights and an array `warehouse` of room heights arranged from left to right. You may reorder the boxes arbitrarily, but boxes can only be inserted from the left entrance. A box can pass through a room only if its height is no greater than the height limit of every room it must pass. Each room can store at most one box. Return the maximum number of boxes that can be placed in the warehouse. 5. **Place boxes into a warehouse from either side** This is the same setup as the previous problem, except each box may be inserted from either the left entrance or the right entrance. You may still reorder the boxes arbitrarily, and each room can hold at most one box. Return the maximum number of boxes that can be placed.

Quick Answer: This set of problems evaluates algorithm design and problem-solving skills across array manipulation, range-update techniques, load-balancing and partitioning strategies, and combinatorial packing, testing competencies in complexity analysis, data-structure use, and optimization under constraints.

Part 1: Minimum Range +/-1 Operations to Match Target

You are given two integer arrays nums and target of equal length. In one operation, choose any contiguous subarray nums[l..r] and either add 1 to every element in that subarray or subtract 1 from every element in that subarray. Return the minimum number of operations needed to transform nums into target.

Constraints

  • 0 <= n <= 2 * 10^5
  • -10^9 <= nums[i], target[i] <= 10^9
  • len(nums) == len(target)
  • The answer can be larger than 32-bit integer range

Examples

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

Expected Output:

Explanation: The needed difference is [1, 1, 1, 2]. One +1 operation on [0..3] and one +1 operation on [3..3] are enough.

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

Expected Output:

Explanation: The difference is [1, -2, 1]. Positive and negative requirements must be handled separately, giving 4 total operations.

Input: ([5, 5], [2, 3])

Expected Output:

Explanation: The difference is [-3, -2]. Subtract 1 on [0..1] twice, then subtract 1 on [0..0] once.

Input: ([], [])

Expected Output:

Explanation: Empty arrays already match.

Hints

  1. Let diff[i] = target[i] - nums[i]. A +1 interval only contributes to positive values of diff, and a -1 interval only contributes to negative values.
  2. For the positive part and the negative part separately, count how much the required height increases as you scan from left to right.

Part 2: Build a Target Array from Zeros Using Range Increments

You start with an array of n zeros. In one operation, choose any contiguous subarray and add 1 to every element in it. Given a target array of non-negative integers, return the minimum number of operations required to build the target array.

Constraints

  • 0 <= n <= 2 * 10^5
  • 0 <= target[i] <= 10^9
  • The answer can be larger than 32-bit integer range

Examples

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

Expected Output:

Explanation: You need 1 layer starting at index 0, another starting at index 1, and another starting at index 2.

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

Expected Output:

Explanation: Build 3 units at index 0, then only 1 new operation is needed when the height rises from 1 to 2 at the end.

Input: ([5],)

Expected Output:

Explanation: A single element of height 5 needs 5 operations.

Input: ([0, 0, 0],)

Expected Output:

Explanation: The zero array already matches the target.

Input: ([],)

Expected Output:

Explanation: Empty target needs no operations.

Hints

  1. Think of target as a skyline or histogram. Each operation paints one horizontal strip over a contiguous segment.
  2. A new operation must start at index i exactly when target[i] is greater than target[i - 1].

Part 3: Minimize the Maximum Load When Assigning Jobs

You are given an array jobs where jobs[i] is the time required for job i, and an integer k for the number of workers. Assign each job to exactly one worker. The load of a worker is the sum of the job times assigned to that worker. Return the minimum possible value of the maximum worker load.

Constraints

  • 0 <= len(jobs) <= 12
  • 1 <= k <= 12
  • 0 <= jobs[i] <= 10^7
  • Each job must be assigned to exactly one worker
  • Workers may receive zero jobs

Examples

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

Expected Output:

Explanation: Each worker can take one job, so the maximum load is 3.

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

Expected Output:

Explanation: One optimal assignment is [8, 2, 1] and [7, 4], so the maximum load is 11.

Input: ([5, 5, 4, 4, 4], 2)

Expected Output:

Explanation: Best possible is 12, for example [5, 5] and [4, 4, 4].

Input: ([10], 5)

Expected Output:

Explanation: There is only one job, so the answer is 10.

Input: ([], 3)

Expected Output:

Explanation: No jobs means no load.

Hints

  1. The answer is between max(jobs) and sum(jobs). Try binary searching that limit.
  2. To check whether a limit works, assign larger jobs first and prune symmetric states where two workers currently have the same load.

Part 4: Place Boxes into a Warehouse from the Left Side

You are given an array boxes of box heights and an array warehouse of room heights from left to right. You may reorder the boxes arbitrarily, but boxes can only be inserted from the left entrance. A box can pass through a room only if its height is no greater than the height limit of every room it must pass. Each room can store at most one box. Return the maximum number of boxes that can be placed in the warehouse.

Constraints

  • 0 <= len(boxes), len(warehouse) <= 10^5
  • 1 <= boxes[i], warehouse[i] <= 10^9
  • Boxes may be reordered arbitrarily
  • Each room can contain at most one box

Examples

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

Expected Output:

Explanation: After prefix-min preprocessing, the usable room heights become [5, 3, 3, 3, 1]. Three boxes can be placed.

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

Expected Output:

Explanation: The effective room heights are [3, 3, 1, 1]. Only three boxes can be placed.

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

Expected Output:

Explanation: All three boxes fit because every room has effective height 3.

Input: ([5], [4])

Expected Output:

Explanation: The box is too tall for the only room.

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

Expected Output:

Explanation: No boxes are available.

Hints

  1. A room's true usable height is limited by the smallest room before it, because every box must pass through that prefix from the left.
  2. After preprocessing those effective heights, put the smallest boxes into the deepest available rooms first.

Part 5: Place Boxes into a Warehouse from Either Side

You are given an array boxes of box heights and an array warehouse of room heights from left to right. You may reorder the boxes arbitrarily, and each box may be inserted from either the left entrance or the right entrance. A box can pass through a room only if its height is no greater than the height limit of every room it must pass. Each room can store at most one box. Return the maximum number of boxes that can be placed.

Constraints

  • 0 <= len(boxes), len(warehouse) <= 10^5
  • 1 <= boxes[i], warehouse[i] <= 10^9
  • Boxes may be reordered arbitrarily
  • Each room can contain at most one box

Examples

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

Expected Output:

Explanation: Using both entrances, the effective room capacities are [3, 3, 1, 2]. Four boxes can be matched.

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

Expected Output:

Explanation: One box can go into the left room from the left and one into the right room from the right.

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

Expected Output:

Explanation: The best split is around the smallest room, giving capacities that fit three boxes.

Input: ([1], [1])

Expected Output:

Explanation: The only box fits in the only room.

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

Expected Output:

Explanation: No boxes are available.

Hints

  1. There is an optimal arrangement with a split point: rooms on one side are effectively filled from the left, and rooms on the other side from the right.
  2. Compute each room's reachable height from the left and from the right, keep the better one, then sort those capacities and greedily match boxes.
Last updated: Apr 19, 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

  • Hierarchical Access Control for an Advertising Platform - Pinterest (medium)
  • First Word Matching Each Prefix Query - Pinterest (medium)
  • Maximize Boxes Stored Through One Entrance - Pinterest (medium)
  • Solve Multiple Coding Interview Problems - Pinterest (medium)
  • Implement a Sparse Matrix Class - Pinterest (medium)