LeetCode 1427, Easy. Topics: Array, Math, String. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 20 parametrized pytest cases, and a playground notebook:
Problem
You are given a string s containing lowercase English letters, and a matrix shift, where shift[i] = [direction<sub>i</sub>, amount<sub>i</sub>]:
direction<sub>i</sub> can be 0 (for left shift) or 1 (for right shift).
amount<sub>i</sub> is the amount by which string s is to be shifted.
- A left shift by 1 means remove the first character of
s and append it to the end.
- Similarly, a right shift by 1 means remove the last character of
s and add it to the beginning.
Return the final string after all operations.
Examples
Constraints
1 <= s.length <= 100
s only contains lower case English letters.
1 <= shift.length <= 100
shift[i].length == 2
direction<sub>i</sub> is either 0 or 1.
0 <= amount<sub>i</sub> <= 100
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
NeetCode All. Last modified on September 7, 2026