Hackerrank - Circular Array Rotation

Hackerrank - Problem Statement

A description of the problem can be found on Hackerrank.

Solution

We rotate the array in circles. That why it is enough to calculate a position after all rotations using modulo. We split the array into two halves at position array_length - calculated_position. We change halves and concat them - the second will be first and the first will be the second.

I created solution in:

All solutions are also available on my GitHub.

Java

JavaScript

Scala

Ruby

Leave a Reply