Give 30 medium Python coding problems with brief solutions
Here are 30 medium-level Python coding problems along with brief solutions to help you practice effectively:
PYTHON DEVELOPER
Find the first non-repeating character in a string
Use a hash map to count character frequency and then find the first with count 1.Merge two sorted linked lists
Use two pointers to merge lists in O(n) time.Implement binary search on a sorted array
Classic divide and conquer approach with mid index comparison.Convert Roman numerals to integer
Map symbols to values and add/subtract based on neighbor comparison.Detect cycle in a linked list
Use Floyd’s Tortoise and Hare algorithm.Longest substring without repeating characters
Sliding window with hash set for tracking characters.Find all pairs in array that sum to a target
Use a hash map to store complements while iterating.Group anagrams from a list of strings
Sort each string as key in a dictionary grouping anagrams.Find kth largest element in an array
Use a min-heap of size k or quickselect algorithm.Valid parentheses checker
Use a stack to match opening and closing braces.Implement a stack with getMin operation in O(1)
Maintain an auxiliary stack to track current minimum.Product of array except self
Calculate prefix and suffix products without division.Rotate array to the right by k steps
Reverse whole array, then reverse first k and last n-k elements.Search in a rotated sorted array
Modified binary search checking rotated halves.Intersection of two arrays
Use sets and find common elements.Find duplicate numbers in array
Use a set to track seen or modify array indices.Number of islands in a grid
Use DFS or BFS to count connected components of 1s.Implement Trie (Prefix Tree)
Use nested dictionaries or classes for nodes.Evaluate Reverse Polish Notation
Use a stack to evaluate based on operators and operands.Find all permutations of a string
Use backtracking to generate permutations.Median of two sorted arrays
Use binary search to partition arrays optimally.Coin change - minimum coins
Dynamic programming approach with bottom-up table.Calculate power(x, n)
Use fast exponentiation (divide-and-conquer).Longest Palindromic Substring
Expand around centers for O(n²) solution.Clone a graph
DFS or BFS with hashmap to copy nodes.Binary tree level order traversal
BFS using queue to collect nodes level-wise.Maximum subarray sum
Kadane’s algorithm with linear scan.Merge intervals
Sort intervals and merge overlapping pairs.Design a parking lot system (OOP)
Model entities and manage spots logically.Implement LRU Cache
Use OrderedDict or combination of hashmap + doubly linked list.
These problems cover widely used algorithmic patterns such as sliding windows, hashing, heaps, recursion/backtracking, dynamic programming, and graph/tree traversals, useful for medium-level Python interview rounds.