Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions