Problem 187604 · medium · Phase 01 Prerequisites & Setup

Conveyor Belt Rotation

strings · slicing · modulo

Letters sit on a circular conveyor belt. Given a string s and an integer k >= 0, move the first k characters to the end (a left rotation by k). Rotating by the length of the string gives back the original, so k may be larger than len(s).

Examples

Input:  s = "abcdef", k = 2
Output: "cdefab"

Input:  s = "abc", k = 4
Output: "bca"

Constraints

  • 0 <= len(s) <= 2000
  • 0 <= k <= 10**6
  • s may contain any printable characters

Goals

  • Rotate a string to the left with two slices
  • Use modulo so large shifts wrap around
  • Handle the empty string
Starting Python…