Live Programming - HackerRank Circular Array Rotation - Part 2

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

A better way to do this would be not to rotate at all. You can just point to the number that would be in the position after the rotation and print that number so you don't actually have to rotate the array which would take a long time. For example if you had array: 1 2 3 4 5 6 and you rotated 3 times which would give you 4 5 6 1 2 3 and you wanted element at position 3 which is 1(Indexing starts at 0). You could just print array[(k+3)%n].

dazzaondmic
join shbcf.ru