Programming, Data Structures And Algorithms Using Python
Please scroll down for latest Programs 👇
Code compiled and tested successfully!
Week 3 Programming Assignment
Due date on 2026-08-14, 23:59 IST
Complete Program
Python
# --- 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
Python
# --- 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 ---
You may submit any number of times before the due date. The final submission will be considered for grading.
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
CompilationSuccessful|Public Test Cases: 9/9 Passed
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.