FastPrepTrain Rotation Reachability Probability
Problems/Train Rotation Reachability Probability

Train Rotation Reachability Probability

IMC Trading logoIMC Trading● EasyNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad online assessment. The goal is the chance that rotations alone work, and it is about 95% the same as the reported three-car puzzle. We chose a uniform random order of cars, a car count you can change, limits, and a numeric tolerance. The multiple-choice pieces in the picture do not make a full answer key.

A train has carCount distinct cars and one fixed target order. Its only allowed move removes the last car and puts that car at the front. The conductor may make zero or more moves.

For this exercise, assume the initial order is chosen uniformly from all permutations, and generalize the three-car case in the first example to the supplied carCount. Return the probability that the conductor can reach the target order.

For this exercise, assume a numeric result with relative-or-absolute tolerance 1e-9. Complete trainRotationProbability(carCount).

Function

trainRotationProbability(carCount: int) → double

Examples

Example 1

carCount = 3return = 0.5

For three distinct cars, exactly three of the six initial orders are cyclic rotations of the target. The result is 3/6 = 0.5 under the stated uniform model.

Example 2

carCount = 1return = 1.0

There is only one initial order; zero moves already reaches the target.

Example 3

carCount = 4return = 0.16666666666666666

Exactly four of the 4! = 24 orders are reachable rotations of the target. The probability is 1/6.

Constraints

  • For this exercise, assume 1 <= carCount <= 12.
  • Every car is distinct; the target order is fixed before the random initial order is chosen.
  • The answer is a probability, rather than a count of arrangements or a yes/no answer for one supplied order.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Enough Muffins for the LineSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Next Pascal Row CoefficientIntuit · OAIntuit interview questions
  • Subarray SumVisa · OAVisa interview questions
  • Drawing EdgeWeRide · OAWeRide interview questions
  • Drawing EdgeIBM · OAIBM interview questions
  • Drawing EdgeSnowflake · OASnowflake interview questions
  • Process SchedulingCitadel · OACitadel interview questions
  • Unique Digits in RangeAgoda · OAAgoda interview questions
  • Find Max Number of PairsRoblox · OARoblox interview questions
  • Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public double trainRotationProbability(int carCount) {
        // Write your solution here.
    }
}
Checking account…