Home > Software design >  I'm working on the algorithm and it only gives an error in 1 case (Runtime Error)
I'm working on the algorithm and it only gives an error in 1 case (Runtime Error)

Time:06-04

Only case 4 gives runtime error. I looked at other answers but couldn't find a solution

case ss

CodePudding user response:

k can be much larger than the length of the array, so your approach is failing since the index is much larger than the array length.

To correctly handle this, make k equal to k modulus array_length, since rotating the array by array_length times effectively makes no changes to the current ordering.

  • Related