Robert Eisele
Engineer, Systems Architect and DBA

Codesignal: nthPlace

Original Problem

My daughter was given the following task: given the first number x and the second number y, find the nth number. The description was quite vague, but my daughter managed to do the task.

Can you?


Turns out, for x = 7, y = 10 and n = 5,
the output should be
nthPlace(x, y, n) = 19.


  • [time limit] 4000ms (js)
  • [input] integer x

    The first number.

    1 ≤ x ≤ y.

  • [input] integer y

    The second number.

    x ≤ y ≤ 100.

  • [input] integer n

    The number to find.

    3 ≤ n ≤ 50.

  • [output] integer

    The nth number.


The solution is simply \(n-1\) times the difference of the upper and lower bound plus the lower bound:

\[s = x + (y - x) \cdot (n - 1)\]

Or as a JavaScript solution:

nthPlace = (x, y, n) =>
   x + (y - x) * --n

« Back to problem overview