Train Rotation Reachability Probability
Updated
Problem statement
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) → doubleExamples
Example 1
carCount = 3return = 0.5For 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.0There is only one initial order; zero moves already reaches the target.
Example 3
carCount = 4return = 0.16666666666666666Exactly 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