โ† BNY Mellon questions

Find Kth good number greater than N

Filed under BNY Mellon

Free read 2 of 3

Confirm if N is given as an integer or string, and the expected range for K.

The question

Find the Kth 'good' number strictly greater than a given number N, where a good number is defined as having a digit sum divisible by 5.

Constraints

  • N can be up to 10^18.
  • K is a small positive integer.
  • Time limit requires efficient searching beyond linear scan.

Examples

Input
N = 4, K = 1
Output
5
Why
Numbers greater than 4 with digit sum divisible by 5: 5 (5%5==0), 9 (9%5!=0), etc. First is 5.

Approach

  1. Confirm if N is given as an integer or string, and the expected range for K.

Tips

  • What they are testing: Test boundary conditions where N itself has a digit sum divisible by 5 (remember we want numbers strictly greater than N).
  • Common mistake: Incrementing N one by one in a loop, which will time out for large N.

Related BNY Mellon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.