Competitive Programming Tasks
Competitive Programming Tasks
Here are some competitive programming tasks you can try in Python, ranging from easy to
challenging:
**Difficulty**: Easy
**Description**: Write a function `fizzbuzz(n: int) -> List[str]` that returns a list of strings representing
the numbers from 1 to `n`. For multiples of three, return "Fizz" instead of the number, and for
multiples of five, return "Buzz". For numbers that are multiples of both three and five, return
"FizzBuzz".
**Difficulty**: Easy
**Description**: Write a function `are_anagrams(s1: str, s2: str) -> bool` that checks if two strings are
anagrams of each other (ignoring spaces and case).
**Difficulty**: Medium
**Description**: Implement the function `two_sum(nums: List[int], target: int) -> List[int]` that takes a
list of integers `nums` and an integer `target`. It should return the indices of the two numbers such
that they add up to the target. You may assume that each input would have exactly one solution, and
you cannot use the same element twice.
**Difficulty**: Medium
**Description**: Write a function `length_of_longest_substring(s: str) -> int` that takes a string `s` and
returns the length of the longest substring without repeating characters.
**Difficulty**: Medium
**Difficulty**: Hard
**Description**: Implement the 0/1 Knapsack problem using dynamic programming. Write a function
`knapsack(weights: List[int], values: List[int], W: int) -> int` that returns the maximum value that can
be put in a knapsack of capacity `W`.
**Difficulty**: Hard
**Description**: Write a function `count_inversions(arr: List[int]) -> int` that returns the number of
inversions in the array. An inversion is a pair of indices (i, j) such that i < j and arr[i] > arr[j]. Use a
modified merge sort to count the inversions efficiently.
**Difficulty**: Hard
**Description**: Given a grid of integers, write a function `min_path_sum(grid: List[List[int]]) -> int`
that computes the minimum path sum from the top-left corner to the bottom-right corner, moving
only down or right.
**Difficulty**: Hard
**Description**: Write a function `palindrome_partition(s: str) -> List[List[str]]` that returns all
possible palindrome partitioning of a string. A palindrome partitioning of a string is a partitioning such
that every substring of the partition is a palindrome.
**Difficulty**: Hard