0% found this document useful (0 votes)
15 views

Competitive Programming Tasks

Uploaded by

attastudy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Competitive Programming Tasks

Uploaded by

attastudy7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

COMPETITIVE PROGRAMMING TASKS

Here are some competitive programming tasks you can try in Python, ranging from easy to
challenging:

### Task 1: FizzBuzz Variation

**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".

### Task 2: Anagram Checker

**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).

### Task 3: Two Sum Problem

**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.

### Task 4: Longest Substring Without Repeating Characters

**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.

### Task 5: Merge Intervals

**Difficulty**: Medium

**Description**: Given a collection of intervals, write a function `merge_intervals(intervals:


List[List[int]]) -> List[List[int]]` that merges all overlapping intervals and returns a new list of non-
overlapping intervals.
### Task 6: Knapsack Problem (0/1)

**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`.

### Task 7: Count Inversions

**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.

### Task 8: Minimum Path Sum

**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.

### Task 9: Palindrome Partitioning

**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.

### Task 10: Largest Rectangle in Histogram

**Difficulty**: Hard

**Description**: Implement the function `largest_rectangle_area(heights: List[int]) -> int` that


calculates the area of the largest rectangle that can be formed in a histogram represented by an array
of heights.

Feel free to ask for solutions or hints on any of these tasks!

You might also like