We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Arrays
  4. Left Rotation

Left Rotation

Problem
Submissions
Leaderboard
Discussions
Editorial

A left rotation operation on an array of size shifts each of the array's elements unit to the left. Given an integer, , rotate the array that many steps left and return the result.

Example

After rotations, .

Function Description

Complete the rotateLeft function in the editor below.

rotateLeft has the following parameters:

  • int d: the amount to rotate by
  • int arr[n]: the array to rotate

Returns

  • int[n]: the rotated array

Input Format

The first line contains two space-separated integers that denote , the number of integers, and , the number of left rotations to perform.
The second line contains space-separated integers that describe .

Constraints

Sample Input

5 4
1 2 3 4 5

Sample Output

5 1 2 3 4

Explanation

To perform left rotations, the array undergoes the following sequence of changes:

Author

[deleted]

Difficulty

Easy

Max Score

20

Submitted By

366808

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy