FastPrepShare Items So One Person Gets the Most
Problems/Share Items So One Person Gets the Most

Share Items So One Person Gets the Most

Expedia logoExpedia● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two entries from Expedia SDE intern campus processes list this task under the title Distribute Items, in a later interview round. One is from interviews on August 14, 2020, and one is from interviews on August 31, 2021. Neither candidate describes it. The rules, the limit n <= 10^9 and two small samples come from a separate card for that title, not from the candidates.

The card's samples count only how many items each person gets, and they count each order of the shares as its own way, so (3, 1, 1) and (1, 3, 1) are two ways. The card does not say whether a large count is reported in full or under a modulus. Here, the full count is returned as a 64-bit integer with no modulus. At n = 10^9 a loop over every share is too slow, so the tests expect a constant-time formula.

Our version is about 80% the same as the reported questions.

You have n identical items and three people, numbered 1, 2 and 3. Give out all n items so that:

  • every person gets at least one item, and
  • exactly one person gets the most items: that person gets strictly more than each of the other two.

A way is described by how many items each person gets. Two ways are different when some person gets a different number of items, so giving (3, 1, 1) and (1, 3, 1) are two different ways.

Return the number of ways. The answer always fits in a 64-bit signed integer.

Function

distributeItems(n: int) → long

Examples

Example 1

n = 7return = 12

Write a way as (person 1, person 2, person 3). The ways with one clear top share are (5, 1, 1), (4, 2, 1), (4, 1, 2), (3, 2, 2) and the other orders of these. (5, 1, 1) and (3, 2, 2) each have 3 orders, and 4, 2, 1 has 6 orders, so there are 3 + 6 + 3 = 12 ways. (3, 3, 1) is not allowed: two people share the top share.

Example 2

n = 9return = 24

There are 28 ways to give out 9 items with at least one each. Remove (4, 4, 1) in its 3 orders and (3, 3, 3), where the top share is shared: 28 - 3 - 1 = 24.

Example 3

n = 2return = 0

With 2 items, one of the three people gets nothing, so no way is allowed.

Constraints

  • 0 <= n <= 10^9

More Expedia Onsite Interview questions

  • Scramble StringONSITE INTERVIEW · Seen Sep 2026
  • Smallest Sufficient TeamONSITE INTERVIEW · Seen Sep 2026
  • Check Anagram Pairs Index by IndexONSITE INTERVIEW · Seen Oct 2025
  • Fresh Oranges Left After Rotting StopsONSITE INTERVIEW · Seen Oct 2025
  • Longest Increasing SubsequenceONSITE INTERVIEW · Seen Oct 2025
  • Lowest Common Ancestor with Repeated and Missing ValuesONSITE INTERVIEW · Seen Oct 2025
  • Shortest Substring with Exactly K OnesONSITE INTERVIEW · Seen Oct 2025
  • Middle Element of a Linked ListONSITE INTERVIEW · Seen Nov 2024
  • Minimum in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Sep 2024
  • Mirror Image Binary TreesONSITE INTERVIEW · Seen Sep 2024

Similar questions at other companies

  • Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
  • Unique Digit Permutations Without Leading ZeroMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • K-th Amount a Payout Machine Can GiveRippling · ONSITE INTERVIEWRippling interview questions
  • Probability of Exactly K HeadsBank of America · ONSITE INTERVIEWBank of America interview questions
  • Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Get Triplet CountIBM · OAIBM interview questions
  • Sum of Pipeline Response TimesBloomberg LP · OABloomberg LP interview questions
  • Count Reverse-Digit PairsVisa · OAVisa interview questions
  • Get Triplet CountPoint72 · OAPoint72 interview questions
  • Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions

Expedia interview experiences

  • Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
  • Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
  • Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
  • Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
  • Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
  • Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)
All Expedia interview questionsSee Expedia hiring insights
Saved
class Solution {
    public long distributeItems(int n) {
        // Write your code here.
    }
}
Checking account…