Programming, Data Structures And Algorithms Using Python
Please scroll down for latest Programs 👇
Code compiled and tested successfully!
Due date on 2026-08-14, 23:59 IST
Complete Program
# --- START OF SOLUTION CODE ---
def contracting(l):
if len(l) < 3:
return True
return (abs(l[1] - l[0]) > abs(l[2] - l[1])) and contracting(l[1:])
def counthv(l):
hills = 0
valleys = 0
for i in range(1, len(l) - 1):
if l[i] > l[i - 1] and l[i] > l[i + 1]:
hills += 1
if l[i] < l[i - 1] and l[i] < l[i + 1]:
valleys += 1
return [hills, valleys]
def leftrotate(m):
size = len(m)
rotated_m = []
for i in range(size):
rotated_m.append([])
for c in range(size - 1, -1, -1):
for r in range(size):
rotated_m[size - (c + 1)].append(m[r][c])
return rotated_m
# --- END OF SOLUTION CODE ---
Code Snippet to Paste in the Editor
# --- START OF SOLUTION CODE ---
def contracting(l):
if len(l) < 3:
return True
return (abs(l[1] - l[0]) > abs(l[2] - l[1])) and contracting(l[1:])
def counthv(l):
hills = 0
valleys = 0
for i in range(1, len(l) - 1):
if l[i] > l[i - 1] and l[i] > l[i + 1]:
hills += 1
if l[i] < l[i - 1] and l[i] < l[i + 1]:
valleys += 1
return [hills, valleys]
def leftrotate(m):
size = len(m)
rotated_m = []
for i in range(size):
rotated_m.append([])
for c in range(size - 1, -1, -1):
for r in range(size):
rotated_m[size - (c + 1)].append(m[r][c])
return rotated_m
# --- END OF SOLUTION CODE ---
This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-20, 23:59 IST
Code Snippet to Paste in the Editor
# --- START OF SOLUTION CODE ---
def frequency(l):
count = {}
for n in l:
if n in count.keys():
count[n] = count[n] + 1
else:
count[n] = 1
minlist = findmin(count)
maxlist = findmax(count)
return ((minlist, maxlist))
def findmin(d):
upperbound = 0
for n in d.keys():
if d[n] > upperbound:
upperbound = d[n]
minlist = []
mincount = upperbound
for n in d.keys():
if d[n] < mincount:
minlist = [n]
mincount = d[n]
elif d[n] == mincount:
minlist.append(n)
return (sorted(minlist))
def findmax(d):
maxlist = []
maxcount = 0
for n in d.keys():
if d[n] > maxcount:
maxlist = [n]
maxcount = d[n]
elif d[n] == maxcount:
maxlist.append(n)
return (sorted(maxlist))
def onehop(l):
direct = {}
for (i, j) in l:
if i in direct.keys():
direct[i].append(j)
else:
direct[i] = [j]
hopping = []
for src in direct.keys():
for dest in direct[src]:
if dest in direct.keys():
for remote in direct[dest]:
if src != remote:
hopping.append((src, remote))
return (remdup(sorted(hopping)))
def remdup(l):
if len(l) < 2:
return (l)
if l[0] != l[1]:
return (l[0:1] + remdup(l[1:]))
else:
return (remdup(l[1:]))
# --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
Due date on 2026-08-27, 23:59 IST
Code Snippet to Paste in the Editor
# --- START OF SOLUTION CODE ---
books = {}
borrowers = {}
checkouts = []
nextline = input().strip()
while nextline.find("Books") < 0:
nextline = input().strip()
nextline = input().strip()
while nextline.find("Borrowers") < 0:
(accession_number, title) = nextline.split('~')
books[accession_number] = title
nextline = input().strip()
nextline = input().strip()
while nextline.find("Checkouts") < 0:
(username, fullname) = nextline.split('~')
borrowers[username] = fullname
nextline = input().strip()
nextline = input().strip()
while nextline.find("EndOfInput") < 0:
(username, accession_number, due_date) = nextline.split('~')
checkoutline = due_date + "~" + borrowers[username] + "~" + accession_number + "~" + books[accession_number]
checkouts.append(checkoutline)
nextline = input().strip()
for checkoutline in sorted(checkouts):
print(checkoutline)
# --- END OF SOLUTION CODE ---This assignment has Public Test cases. Please click on "Compile & Run" button to see the status of Public test cases. Assignment will be evaluated only after submitting using Submit button below. If you only save as or compile and run the Program, your assignment will not be graded and you will not see your score after the deadline.
Evaluation Results
Note: These tests may not be considered while scoring.
No comments:
Post a Comment
Keep your comments reader friendly. Be civil and respectful. No self-promotion or spam. Stick to the topic. Questions welcome.