Programming, Data Structures And Algorithms Using Python - Week 3 Programming Assignment Jul-Dec 2022

   NPTEL PROGRAMMING ASSIGNMENTS

Programming, Data Structures And Algorithms Using Python

Week 3 Programming Assignment
Last Day of Submission: 18-Aug-2022

1. Write a function contracting(l) that takes as input a list of integer l and returns True if the absolute difference between each adjacent pair of elements strictly decreases.

 
Input Function:
 contracting([9,2,7,3,1])
Output: 
  True



2. 
In a list of integers lthe neighbours of l[i] are l[i-1] and l[i+1]l[i] is a hill if it is strictly greater than its neighbours and a valley if it is strictly less than its neighbours. Write a function counthv(l) that takes as input a list of integers l and returns a list [hv, vc] where hc is the number of hills in l and vc is the number of valleys in l.


Input Function:
 counthv([1,2,1,2,3,2,1])
Output: 
  [2, 1]



3. 
Write a function leftrotate(m) that takes a list representation m of a square matrix as input, and returns the matrix obtained by rotating the original matrix counterclockwize by 90 degrees.


Input Function:
 leftrotate([[1,2,3],[4,5,6],[7,8,9]])
Output: 
  [[3, 6, 9], [2, 5, 8], [1, 4, 7]]





Here are some examples of how your function should work.



 

 


Post a Comment (0)
Previous Post Next Post