Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assemble Conga Line Have you ever heard the term conga line? Basically, it s a carnival dance where the dancers form a long line. Everyone

Assemble Conga Line
Have you ever heard the term conga line? Basically, its a carnival dance where the dancers form a long line. Everyone holds the waist of the person in front of them and their waists are held in turn by the person to their rear, excepting only those in the front and the back. It kind of looks like this-
By now, you can quite understand the suitable data structure to represent a conga line. Now you are the choreographer of the Conga Dance in a Summer Festival. You wish to arrange the conga line ascending age wise and tell the participants to stand in a line likewise. Now as technical you are, can you write a method that will take the conga line and return True if everyone stands according to your instruction. Otherwise returns False.
Sample Input
10->15->34->41->56->72
Sample Input
10->15->44->41->56->72
Sample Output
True
Sample Output
False
You must Run this cell for your driver code to execute successfully
#Run this cell
class Node:
def __init__(self,elem,next = None):
self.elem,self.next = elem,next
def createList(arr):
head = Node(arr[0])
tail = head
for i in range(1,len(arr)):
newNode = Node(arr[i])
tail.next = newNode
tail = newNode
return head
def printLinkedList(head):
temp = head
while temp != None:
if temp.next != None:
print(temp.elem, end ='-->')
else:
print(temp.elem)
temp = temp.next
print()
Driver code:
def assemble_conga_line(conga_line):
#TO DO
print('==============Test Case 1=============')
conga_line = createList(np.array([10,15,34,41,56,72]))
print('Original Conga Line: ', end ='')
printLinkedList(conga_line)
returned_value = assemble_conga_line(conga_line)
print(returned_value) #This should print True
unittest.output_test(returned_value, True)
print()
print('==============Test Case 2=============')
conga_line = createList(np.array([10,15,44,41,56,72]))
print('Original Conga Line: ', end ='')
printLinkedList(conga_line)
returned_value = assemble_conga_line(conga_line)
print(returned_value) #This should print False
unittest.output_test(returned_value, False)
print()

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

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago