FastPrepMinimum Parking Roof Length
Problems/Minimum Parking Roof Length

Minimum Parking Roof Length

American Express logoAmerican Express● EasyFULLTIMEOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The original report asks for one contiguous roof of minimum integer length covering at least k cars. It does not define the length convention or coordinate bounds. This practice version uses distinct integer positions and inclusive length.

You are given distinct nonnegative integer coordinates in positions, where each coordinate contains one parked car, and an integer k.

Install one contiguous roof that covers at least k cars. A roof spanning integer coordinates x through y, inclusive, has length y - x + 1.

Return the minimum possible roof length.

Function

minimumRoofLength(positions: int[], k: int) → long

Examples

Example 1

positions = [2,10,8,17]k = 3return = 9

A roof from position 2 through position 10 covers cars at 2, 8, and 10 and has length 9.

Example 2

positions = [1,2,3]k = 1return = 1

A length-one roof can cover any single car.

Example 3

positions = [7,3,12,4,8]k = 3return = 5

Either positions 3, 4, and 7 or positions 4, 7, and 8 fit under a roof of length 5.

Constraints

  • 1 <= positions.length <= 100000
  • 0 <= positions[i] <= 1000000000
  • All positions are distinct.
  • 1 <= k <= positions.length

More American Express interview questions

  • Maximum Points in a Perimeter-Bounded RectangleOA · Seen Sep 2026
  • Minimum Moves to Spread Stones Across a GridOA · Seen Sep 2026
  • Largest Two Non-Overlapping Buildable SquaresOA · Seen Aug 2026
  • Maximum Sum of Two Sign-Flipping WindowsOA · Seen Aug 2026
  • Crop Text at a Whole-Word BoundaryOA · Seen Aug 2026
  • Minimum Pile Reduction StepsOA · Seen Aug 2026
  • Disjoint Target-Sum TripletsPHONE SCREEN · Seen Mar 2025

Similar questions at other companies

  • Count Max Num Teams 🥝Amazon · OA
  • Sliding Window MedianAuxoAI · OA
  • Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
  • Maximum Requests in WindowSalesforce · OASalesforce interview questions
  • Earliest Hour with Frequent Badge AccessIntuit · OAIntuit interview questions
  • Choose One from Each Set to Minimize the RangeInMobi · OAInMobi interview questions
  • Fairest Chocolate PacketsAdobe · PHONE SCREENAdobe interview questions
  • Integer Compression OffsetHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
  • Sliding Window Average After Trimming Both EndsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
All American Express interview questionsSee American Express hiring insights
Saved
class Solution {
    public long minimumRoofLength(int[] positions, int k) {
        // Write your code here.
    }
}
Checking account…