Skip to main content

Posts

Showing posts from July, 2025

Poridhi: Stacks & Queues

  Stacks & Queues related problems: This collection of solutions tackles three classic problems often encountered in technical interviews and competitive programming. The Valid Parentheses problem checks whether a string has properly matched and ordered brackets using a stack. The Sliding Window Maximum efficiently finds the maximum value in every window of size k across an array using a deque, a popular sliding window pattern that ensures optimal performance. The Stock Span Problem simulates a real-world stock analysis scenario and calculates the number of consecutive days before today for which the stock price was less than or equal to today's, also utilizing a stack for efficient computation. These problems test understanding of stacks, queues, and sliding window techniques. ✅ Valid Parentheses def isValid ( s: str ) -> bool : stack = [] mapping = { ')' : '(' , '}' : '{' , ']' : '[' } for char in s: ...

Poridhi: Sorting & Searching

Sorting & Searching related problems: This blog post presents efficient Python solutions to four commonly encountered algorithmic problems that involve arrays and linked lists. It begins with the Merge Intervals problem, which focuses on combining overlapping intervals into consolidated ranges—commonly used in scheduling or time-based tasks. Next, it addresses the Find Minimum in Rotated Sorted Array, helping identify the smallest element in a rotated array using binary search. The Search in Rotated Sorted Array problem is tackled next, showing how to locate a target value even when the array has been pivoted. Finally, the post explains how to Merge Two Sorted Linked Lists, a classic linked list problem often asked in coding interviews, which involves combining two already sorted lists into one while maintaining order. Together, these solutions reinforce understanding of sorting, binary search, and linked list traversal—all essential for technical interviews and real-world developm...

Poridhi: Heaps & Priority Queues

Heaps & Priority Queues related  problems : In this blog post, we tackle three widely asked coding interview questions that revolve around the use of data structures and efficient algorithm design: Kth Largest Element in an Array, LRU Cache, and Min Stack. Each problem requires a strategic approach to managing and retrieving data under specific constraints, making them excellent practice for mastering Python collections and optimizing performance. First, the Kth Largest Element in an Array problem is a classic selection problem that can be efficiently solved using a min-heap. Instead of sorting the entire array, we maintain a heap of the k largest elements seen so far and simply return the smallest among them. This reduces time complexity and enhances performance on large datasets. Next, the LRU (Least Recently Used) Cache is a real-world inspired problem that simulates caching behavior. We use Python's OrderedDict to maintain insertion order, allowing us to quickly update rece...

Poridhi: Backtracking

Backtracking related problems: This blog covers three classic problems— Subsets , Combination Sum , and Word Search —that are efficiently solved using the backtracking technique. The Subsets problem generates all possible combinations (or power sets) of a given list, illustrating how choices can be included or excluded recursively. Combination Sum focuses on finding all unique combinations of numbers that add up to a target value, allowing repetition of elements while pruning paths that exceed the target. Finally, Word Search demonstrates how backtracking can be applied to traverse a 2D grid to determine whether a given word can be formed through sequential horizontal or vertical movements. These examples showcase the power and flexibility of backtracking in solving combinatorial and search-based problems. ✅ Subsets Problem: Generate all possible subsets (the power set) of a given list of numbers. def subsets ( nums ): res = [] def backtrack ( start, path ): res...

Poridhi: Dynamic Programming

Dynamic Programming related problems: This blog post presents Python solutions to six classic dynamic programming problems that frequently appear in coding interviews and competitive programming. These problems include strategies for maximizing profit without choosing adjacent houses in House Robber, decoding numeric strings into alphabetic representations in Decode Ways, and counting unique paths in a grid in Unique Paths. It also covers determining reachability in an array using jumps in Jump Game, finding the longest increasing subsequence in a list of numbers in Longest Increasing Subsequence, and checking if a string can be segmented into dictionary words in Word Break. Each solution is designed using efficient DP techniques such as tabulation and memorization, helping readers understand the core ideas behind dynamic problem-solving in Python. ✅ House Robber def rob ( nums ): if not nums: return 0 if len (nums) <= 2 : return max (nums) dp = [ 0 ] * len (...

Poridhi: Graph

Graph  related problems: This blog post explores four fundamental problems that test your understanding of graph traversal, depth-first search (DFS), breadth-first search (BFS), and backtracking algorithms. It starts with Number of Islands , where we determine how many separate land masses exist in a 2D grid using DFS. Next is Clone Graph , which involves creating a deep copy of a graph structure using recursion and hash mapping. The Course Schedule problem tackles the concept of topological sorting and cycle detection in a directed graph to determine if all courses can be finished. Lastly, Word Search demonstrates backtracking by checking whether a word exists in a grid by moving in four directions. Together, these problems provide essential practice for mastering graph and grid-based problem-solving techniques. ✅  Number of Islands (Problem: Count connected land areas in a 2D grid) def numIslands ( grid ): if not grid: return 0 def dfs ( r, c ): ...

Poridhi: Trees & BST

Trees & BST  related problems: This blog post presents essential Python solutions for foundational binary tree problems, frequently encountered in coding interviews and algorithm practice. It begins by solving how to determine the maximum depth of a binary tree, which measures the height of the tree using recursion. Next, it explains how to invert a binary tree, flipping the left and right children recursively. The level order traversal solution demonstrates how to use a queue for breadth-first search to return all nodes level by level. To check whether a tree is a mirror of itself (symmetric tree), it uses a recursive helper function comparing mirrored subtrees. Further, the blog tackles validation of a binary search tree (BST) by checking whether each node falls within valid numeric boundaries during traversal. It then demonstrates how to find the lowest common ancestor (LCA) of two nodes in a BST using value comparisons. Lastly, the post includes a method to construct a bina...

Poridhi: Basic Recursion

Basic recursion related problems: This blog covers a series of beginner-friendly yet essential programming problems that introduce the fundamentals of function calling, recursion, iteration, and array/string manipulation using Python. It starts by explaining how general and recursive function calls work, which is crucial for understanding how code execution flows in both linear and self-referential contexts. Following that, it dives into classic number-printing problems such as printing from 1 to N, N to 1 in reverse, and from 0 to N-1, all of which build a strong foundation in loops and control structures. The blog also addresses basic computational tasks like finding the sum or product (factorial) of the first N natural numbers—important exercises that enhance logical reasoning and mathematical thinking. Additionally, it includes common problems involving arrays and strings such as reversing an array and checking if a string is a palindrome, both of which are widely used in real-worl...

Poridhi: Linked Lists

Linked Lists  related problems: This collection of Python solutions focuses on essential linked list and cache-related problems that frequently appear in coding interviews and real-world system design. It starts with basic operations like merging two sorted linked lists, reversing a list, and finding the middle or removing the nth node from the end. These problems build a solid foundation in manipulating pointers and understanding node traversal. Additionally, the blog includes problems that require smart traversal strategies like cycle detection, detecting intersections, and finding duplicate numbers using Floyd’s Tortoise and Hare algorithm. More complex scenarios are also covered, such as designing a fully functional custom Linked List and LRU Cache , which help readers understand object-oriented design and memory-efficient structures. Real-world use cases like browser history management and reordering lists for UI rendering are also included to demonstrate how linked lists can...