Problems on lists

 

problem statements

  1. Sum of Elements: Write a program that takes a list of numbers as input and returns the sum of all the elements in the list.


  2. Average of Elements: Write a program that takes a list of numbers as input and returns the average of all the elements in the list.


  3. Reverse a List: Write a program that takes a list as input and returns a new list that is the reverse of the input list.


  4. Find Maximum and Minimum: Write a program that takes a list of numbers as input and returns the maximum and minimum numbers in the list.




  1. Remove Duplicates: Write a program that takes a list as input and returns a new list with duplicates removed.


  2. List Comprehensions: Use list comprehensions to create a new list that contains only the even numbers from a given list of numbers.


  3. Merge Lists: Write a program that takes two lists as input and returns a new list that contains all the elements from both lists, in order.


  4. Sort a List: Write a program that takes a list of numbers as input and returns a new list with the numbers sorted in ascending order.


  5. Find Common Elements: Write a program that takes two lists as input and returns a new list that contains only the elements that are common to both lists.


  6. Matrix Operations: Write a program that performs matrix addition, subtraction, or multiplication using lists of lists as input.

  1. Transpose a Matrix: Write a program that takes a matrix (list of lists) as input and returns the transpose of the matrix.


  2. Rotate a Matrix: Write a program that takes a matrix (list of lists) as input and rotates it 90 degrees clockwise.


  3. Matrix Multiplication: Write a program that takes two matrices (lists of lists) as input and returns their product.


  4. Pascal's Triangle: Write a program that generates Pascal's triangle up to a given number of rows as a list of lists.


  5. Remove Negatives: Write a program that takes a list of numbers as input and removes all negative numbers from the list.


  6. Split List into Sublists: Write a program that takes a list and a number as input and splits the list into sublists of the given size.


  7. Merge Intervals: Write a program that takes a list of intervals (as tuples) and merges overlapping intervals.


  8. Circular List Rotation: Write a program that takes a list and a number as input and performs a circular rotation of the list to the right by the given number of steps.


  9. Longest Increasing Subsequence: Write a program that takes a list of numbers as input and finds the length of the longest increasing subsequence.


  10. Matrix Spiral Order: Write a program that takes a matrix (list of lists) as input and returns its elements in spiral order.