FastPrepRecover the Initial Mango Pile
Problems/Recover the Initial Mango Pile

Recover the Initial Mango Pile

LSEG logoLSEG● EasyFULLTIMEONSITE INTERVIEW

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report fixes three thieves, 22 mangoes left and an initial pile below 100. The reversal rule matches at about 85%; this exercise parameterizes the thief count and remaining amount while retaining that initial bound.

A pile initially contains between 1 and 99 mangoes. Each of thieves people visits it in turn.

Before every visit, the pile has size 3q + 1 for some integer q >= 0. The thief eats the one extra mango, takes one share of q mangoes, and leaves the other two shares, or 2q mangoes.

After all visits, remaining mangoes are left. Return the initial pile size. The inputs are guaranteed to describe exactly one valid initial pile under these rules.

Function

initialMangoes(thieves: int, remaining: int) → int

Examples

Example 1

thieves = 3remaining = 22return = 79

Starting from 79, the pile becomes 52, then 34, then 22 after the three visits.

Example 2

thieves = 1remaining = 0return = 1

The thief eats the single mango and takes a zero-sized share, leaving zero.

Example 3

thieves = 2remaining = 18return = 43

The two forward transitions are 43 to 28 and 28 to 18.

Constraints

  • 1 <= thieves <= 3.
  • 0 <= remaining <= 64.
  • The inputs describe a valid process starting from a unique integer pile size between 1 and 99, inclusive.

More LSEG interview questions

  • Implement Stack Push and Pop OperationsONSITE INTERVIEW · Seen Feb 2025
  • Retrieve Every Student RecordONSITE INTERVIEW · Seen Sep 2024
  • Count Times Using at Most Two DigitsOA · Seen Jul 2025
  • Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
  • Maximum Word Count in a SentenceOA · Seen Jul 2025
  • Minimum Digit Swaps for the Smallest DifferenceOA · Seen Jul 2025
  • Smallest String After at Most One DeletionOA · Seen Jul 2025
  • Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
  • Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
  • Transform a String with at Most One OperationOA · Seen Feb 2025

Similar questions at other companies

  • Generate an Unbiased Bit from a Biased CoinGoogle · ONSITE INTERVIEWGoogle interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
  • 100 DoorsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Clock Hand Angle with Subsecond PrecisionScale AI · ONSITE INTERVIEWScale AI interview questions
  • Estimate Pi from Sampled PointsJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Add Two Numeric Strings with CarryZipRecruiter · ONSITE INTERVIEWZipRecruiter interview questions
  • Three- and Five-liter Jug PlanXilinx · ONSITE INTERVIEWXilinx interview questions
  • Add Two Numbers Given as Digit ArraysCapital One · ONSITE INTERVIEWCapital One interview questions
  • Babysitter Quote with Hourly RatesUpstart · ONSITE INTERVIEWUpstart interview questions
  • Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions

Interview reports that mention this question

  • LSEG Graduate Technology OA and Interviews: 7 Experiences
All LSEG interview questionsSee LSEG hiring insights
Saved
class Solution {
    public int initialMangoes(int thieves, int remaining) {
        // write your code here
    }
}
Checking account…