InterviewStack.io LogoInterviewStack.io

Medium Difficulty Coding Problems Questions

Practice and master medium difficulty algorithmic coding problems that commonly appear in technical interviews. Topics include arrays, strings, linked lists, trees, graphs, hash tables, and dynamic programming. Typical techniques to know are two pointer methods, sliding window, breadth first search and depth first search, recursion and backtracking, memoization and bottom up dynamic programming, sorting and greedy heuristics, and common data structure operations. Interviewers evaluate systematic problem solving: clarifying requirements, designing a correct solution, explaining time and space complexity, handling edge cases and input validation, writing clean and working code in your chosen language, and then iterating to optimize performance. Candidates should be comfortable explaining tradeoffs between approaches, testing with example cases, and communicating thought process clearly while coding under time constraints.

EasyTechnical
46 practiced
Implement a function in Python to reverse a singly linked list in-place and return the new head. Given the head node of a singly linked list, reverse the list iteratively in O(n) time and O(1) extra space. Example:Input: 1 -> 2 -> 3 -> 4 -> 5Output: 5 -> 4 -> 3 -> 2 -> 1Describe edge cases (empty list, single node) and provide clean, well-commented code. Explain time and space complexity and any pointer pitfalls.
HardTechnical
62 practiced
Sliding Window Median (Python): given an array nums and a sliding window size k, return the median for each sliding window as it moves from left to right. Implement the solution using two heaps (max-heap for lower half and min-heap for upper half) with lazy-deletion to support removals. Discuss complexity and balancing heaps for odd/even k.
HardTechnical
53 practiced
Kth Smallest Element in a Sorted Matrix (Python): given an n x n matrix where each of the rows and columns is sorted in ascending order, return the k-th smallest element in the matrix. Provide solutions using a min-heap or binary search on value range; explain when each approach is preferable and analyze time/space complexity for both.
MediumTechnical
49 practiced
Top K Frequent Elements (Python): given an integer array nums and integer k, return the k most frequent elements. Implement an efficient solution using a hashmap to count frequencies followed by a min-heap of size k or bucket sort. Discuss time/space trade-offs and behavior when k is large (close to n).
MediumTechnical
48 practiced
Clone Graph (Python): given a reference of a node in a connected undirected graph where each node contains a list of its neighbors, return a deep copy (clone) of the graph. Implement using BFS or DFS and a hashmap to keep mapping from original to clone. Handle empty graph and large graphs with cycles.

Unlock Full Question Bank

Get access to hundreds of Medium Difficulty Coding Problems interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.