This repository contains solutions to several algorithmic problems implemented in Python.
The tasks demonstrate different algorithmic techniques including:
- hash tables
- greedy algorithms
- dynamic programming
- combinatorics and string analysis
Each file contains:
- problem solution
- function implementation
- unit tests using
assert
Given a list of clubs and their members, determine how many students belong to exactly
Example input:
2 robotics:1,2,3 chess:2,4,5 drama:1,2,6
The algorithm counts the occurrences of each student ID using a dictionary.
Time complexity:
where
Implementation:
k_clubs(input_string)
Given a set of events with start and end times, determine the maximum number of events that can be scheduled without overlap.
Example:
pyramids:1-5 rome:2-4 renaissance:5-8 revolution:6-9
The solution uses a greedy algorithm:
- sort events by finishing time
- always choose the earliest finishing event.
Time complexity:
due to sorting.
Implementation:
max_events(input_string)
Determine the minimum number of ingredients needed to achieve a desired magic power.
Example:
11 1 5 6
The solution uses dynamic programming similar to the classic coin change problem.
Let:
-
$P$ — desired power -
$a_i$ — power of ingredient$i$
DP relation:
Time complexity:
where:
-
$P$ — target power -
$n$ — number of ingredients.
Implementation:
magic_power(input_string)
A word can form a palindrome if at most one character has odd frequency.
Condition:
Example:
aab abc racecar hello
Result:
2
because:
aab → abaracecar → racecar
Time complexity:
where:
-
$n$ — number of words -
$m$ — average word length.
Implementation:
count_palindromic_anagrams(text)
This repository was created to practice:
- algorithm design
- Python problem solving
- greedy algorithms
- dynamic programming
- hash-based counting techniques.