FastPrepMinimum Document Padding for GPU Buckets
Problems/Minimum Document Padding for GPU Buckets

Minimum Document Padding for GPU Buckets

Amazon logoAmazon● HardNEW GRADPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon new grad phone screen. The report gives the goal of putting documents into buckets, the number of GPU batches, how padding works, and a dynamic programming approach. But its written inequality reverses the relationship between documents and groups. Our version uses exactly that DP model, with one or more documents per batch. It is about 94% the same as the reported question.

You have lengths.length documents that must be split into exactly groups non-empty GPU batches. Every document in one batch is padded to the length of the longest document in that batch.

If a batch contains document lengths x1, x2, ..., xm and its maximum is M, that batch adds m * M - (x1 + x2 + ... + xm) padding units.

Return the minimum total padding over all batches. You may reorder documents before batching. Documents with similar lengths can therefore be grouped together.

Function

minimumPadding(lengths: int[], groups: int) → long

Examples

Example 1

lengths = [2,3,7,8]groups = 2return = 2

After sorting, use batches [2,3] and [7,8]. Each batch adds one padding unit, for a total of 2.

Example 2

lengths = [5,5,5]groups = 2return = 0

All documents already have equal length, so every valid two-batch split uses zero padding.

Example 3

lengths = [1,4,7]groups = 1return = 9

The only batch pads all three documents to length 7, adding (7 - 1) + (7 - 4) + (7 - 7) = 9 units.

Constraints

  • 1 <= groups <= lengths.length <= 200.
  • 1 <= lengths[i] <= 10^6.
  • Every batch must contain at least one document.

More Amazon Phone Screen questions

  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
  • Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Cheapest Order to Cut a RodAdobe · PHONE SCREENAdobe interview questions
  • Match Shops and BuyersGoogle · PHONE SCREENGoogle interview questions
  • Longest Chain of Nested BoxesBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Russian Doll EnvelopesInMobi · ONSITE INTERVIEWInMobi interview questions
  • Russian Doll EnvelopesAirbnb · ONSITE INTERVIEWAirbnb interview questions
  • Alternating Jumps to the Last IndexExpedia · OAExpedia interview questions
  • Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
  • Maximum Taxi EarningsWells Fargo · OAWells Fargo interview questions
  • Recursive Display SortFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Split Array to Minimize the Largest SumNation with NaMo · PHONE SCREEN

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public long minimumPadding(int[] lengths, int groups) {
      // Write your code here
    }
}
Checking account…