Skip to content
DeepForgeby svx
All problems
EasyData Structuresds-139

Circular Deque Rotation

Problem

Simulate rotations and end queries on a circular deque.

nums is the starting sequence and operations contains "rotate_left", "rotate_right", "front", "back", or "to_list"; values gives the rotation step count (ignored otherwise). Rotations use k modulo the current length, and front and back return None when the deque is empty.

Return the list of recorded results.

Hint

Reduce the rotation count modulo the current length first.

Test cases

case 1
in: [[1,2,3,4],["rotate_left","to_list","rotate_right","front"],[1,0,2,0]]
expected: [null,[2,3,4,1],null,4]
case 2
in: [[1,2,3],["rotate_left","rotate_left","rotate_left","to_list"],[1,1,1,0]]
expected: [null,null,null,[1,2,3]]
case 3
in: [[],["front","back","to_list"],[0,0,0]]
expected: [null,null,[]]
case 4
in: [[1,2,3],["rotate_right","to_list"],[4,0]]
expected: [null,[3,1,2]]
Starter codePython
def circular_deque_rotation(nums, operations, values):
    # Your code here
    pass

4 test cases · run your code against them in the editor