FastPrepMinimum Nonreciprocal Bandits

Minimum Nonreciprocal Bandits

IMC Trading logoIMC Trading● EasyNEW GRADOA
Learn

Problem statement

Every bandit must aim at exactly targetsPerBandit distinct other bandits. A bandit cannot aim at itself, and no pair may aim at each other.

Find the minimum number of participating bandits for which this is possible. For this exercise, assume the reported two-target puzzle is generalized to the supplied positive target count, with an exact integer result. You only return the minimum count; you do not output a targeting arrangement.

Complete minimumBandits(targetsPerBandit).

Function

minimumBandits(targetsPerBandit: int) → int

Examples

Example 1

targetsPerBandit = 2return = 5

The reported two-target case needs five bandits. Arrange them in a cycle and let each aim at the next two; no pair aims at each other.

Example 2

targetsPerBandit = 1return = 3

Three bandits can form one directed cycle. Two bandits would have to aim at each other.

Example 3

targetsPerBandit = 3return = 7

In a cycle of seven, each bandit aims at the next three. The reverse offsets are four through six, so no reciprocal pair occurs.

Constraints

  • For this exercise, assume 1 <= targetsPerBandit <= 1000000000.
  • All required targets are distinct and different from the aiming bandit.
  • The returned minimum fits a signed 32-bit integer.

More IMC Trading problems

See IMC Trading hiring insights
public int minimumBandits(int targetsPerBandit) {
    // Write your solution here.
}
targetsPerBandit2
expected5
Checking account…