Skip to content
Logo
Terrible Whiteboard

Solving Algorithms One Whiteboard at a Time

  • Home
  • Blog
  • Contact
  • Coupons and Discounts
  • Search

Rotate Array | LeetCode 189 (Pop / Unshift)

Uncategorized

Link to the reverse method.

AFFILIATE LINKS

Great resource I use to learn algorithms.
40% off Tech Interview Pro: http://techinterviewpro.com/terriblewhiteboard
20% off CoderPro: http://coderpro.com/terriblewhiteboard

Here is the full implementation.

let rotate = function(nums, k) {
  k = k % nums.length;
    
  while (k > 0) {
    nums.unshift(nums.pop());
    k--;
  }
};

Post navigation

← Previous Post
Next Post →
Udemy Course: Data Structures and Algorithms

Recent Posts

  • Add Two Numbers | LeetCode 2
  • Odd Even Linked List | LeetCode 328
  • Find the Town Judge | LeetCode 997
  • Jump Game | LeetCode 55
  • Partition Equal Subset Sum | LeetCode 416

Archives

  • May 2020
  • April 2020
  • March 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019

Categories

  • Uncategorized
terriblewhiteboard@gmail.com
Copyright © 2025 Terrible Whiteboard