List
List
Write a function rotate_list(lst, k) that rotates the elements of the list lst to the right by k positions.
The rotation should be in-place.
python
Copy code
Example:
python
Copy code
Create a function group_anagrams(words) that takes a list of strings and groups the anagrams
together. Return a list of lists, where each inner list contains words that are anagrams of each other.
python
Copy code
def group_anagrams(words):
Example:
python
Copy code
Write a function max_subarray_sum(lst) that finds the maximum sum of any contiguous subarray
within the list. You can use Kadane’s algorithm for this problem.
python
Copy code
def max_subarray_sum(lst):
# Your code here
Example:
python
Copy code
max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) # Output: 6 (subarray: [4, -1, 2, 1])
Create a function merge_intervals(intervals) that takes a list of intervals (each interval is a list of two
integers) and merges overlapping intervals. Return a new list of merged intervals.
python
Copy code
def merge_intervals(intervals):
Example:
python
Copy code
Write a function find_missing_number(lst, n) that finds the missing number in a list of integers from
1 to n. The list will contain n-1 integers.
You are given a list lst and an integer k. Rotate the list to the right by k positions in place.
python
Copy code
# Example
lst = [1, 2, 3, 4, 5]
k=2
# Your code here to rotate lst
# Output: [4, 5, 1, 2, 3]
Given a list of strings words, group the anagrams together in a new list of lists.
python
Copy code
# Example
You are given a list of integers lst. Find the maximum sum of any contiguous subarray using Kadane's
algorithm.
python
Copy code
# Example
You have a list of intervals, where each interval is represented as a list of two integers. Merge all
overlapping intervals and return the merged intervals.
python
Copy code
# Example
Given a list of integers from 1 to n with one number missing, identify the missing number without
using any user-defined functions.