Question: Please specify the feedback so u can edit the question if it's still unclear skeleton file and test case: https://drive.google.com/file/d/1dPu7ShSm48FMgt7PNP5cPtmrwbx56v-c/view?usp=sharing Document https://drive.google.com/file/d/1anPK-bdXUxQ4vd5_vrDTAcTH7_Ci-YZC/view?usp=sharing What I ask

Please specify the feedback so u can edit the question if it's still unclear

skeleton file and test case:

https://drive.google.com/file/d/1dPu7ShSm48FMgt7PNP5cPtmrwbx56v-c/view?usp=sharing

Document

https://drive.google.com/file/d/1anPK-bdXUxQ4vd5_vrDTAcTH7_Ci-YZC/view?usp=sharing

What I ask (you can see the details in the document):

rotate(self, steps: int) -> None:

This method 'rotates' the linked list by shifting the position of its elements right or left steps

number of times. If steps is a positive integer, elements should be rotated right. Otherwise,

the elements should be rotated left. All work must be done "in place" without creating any

new nodes. You are not allowed to change the values of the nodes; the solution must

change node pointers. Please note that the value of the steps parameter can be very large

(from -109 to 109). The solution's runtime complexity must be O(N), where N is the length

of the list.

Solution Performance Checker: The allowance factor for this problem is 10.

Example #1:

source = [_ for _ in range(-20, 20, 7)]

for steps in [1, 2, 0, -1, -2, 28, -100]:

lst = CircularList(source)

lst.rotate(steps); print(lst, steps)

Output:

CDLL [15 <-> -20 <-> -13 <-> -6 <-> 1 <-> 8] 1

CDLL [8 <-> 15 <-> -20 <-> -13 <-> -6 <-> 1] 2

CDLL [-20 <-> -13 <-> -6 <-> 1 <-> 8 <-> 15] 0

CDLL [-13 <-> -6 <-> 1 <-> 8 <-> 15 <-> -20] -1

CDLL [-6 <-> 1 <-> 8 <-> 15 <-> -20 <-> -13] -2

CDLL [-6 <-> 1 <-> 8 <-> 15 <-> -20 <-> -13] 28

CDLL [8 <-> 15 <-> -20 <-> -13 <-> -6 <-> 1] -100

Example #2:

lst = CircularList([10, 20, 30, 40])

for j in range(-1, 2, 2):

for _ in range(3):

lst.rotate(j); print(lst)

Output:

CDLL [20 <-> 30 <-> 40 <-> 10]

CDLL [30 <-> 40 <-> 10 <-> 20]

CDLL [40 <-> 10 <-> 20 <-> 30]

CDLL [30 <-> 40 <-> 10 <-> 20]

CDLL [20 <-> 30 <-> 40 <-> 10]

CDLL [10 <-> 20 <-> 30 <-> 40]

Example #3:

lst = CircularList()

lst.rotate(10)

print(lst)

Output:

CDLL []

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!