Fairest Chocolate Packets
Updated
Problem statement
There are packets.length packets of chocolate, and packet i holds packets[i] pieces. You must hand one packet to each of m students, so you choose exactly m different packets.
The spread of a choice is the largest number of pieces among the chosen packets minus the smallest. Return the smallest spread you can get.
Function
minPacketSpread(packets: int[], m: int) → intExamples
Example 1
packets = [15,4,22,9,11,30,6]m = 3return = 5Sorted, the packets are 4, 6, 9, 11, 15, 22, 30. Taking 4, 6, 9 gives a spread of 9 - 4 = 5, and so does 6, 9, 11. No three packets are closer, so the answer is 5.
Example 2
packets = [8,8,3,8]m = 3return = 0The three packets of 8 have a spread of 0.
Example 3
packets = [40,1,25]m = 3return = 39Every packet must be given out, so the spread is 40 - 1 = 39.
Constraints
1 <= m <= packets.length <= 50001 <= packets[i] <= 10^9
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Integer Compression OffsetHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Tagged Metric Window SumsDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Maximum Visible DronesAnduril · PHONE SCREENAnduril interview questions
- Minimum Parking Roof LengthAmerican Express · OAAmerican Express interview questions
- Count Max Num Teams 🥝Amazon · OA
- Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Sliding Window MedianAuxoAI · OA
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
Interview reports that mention this question
Adobe interview experiences
- Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
- Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
- Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
- Adobe New Grad MTS Interview Questions: 7 Experiences
- Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)