πΊοΈ Problem Map
A chronological journal of all 40 DSA problems solved in the AlgoChronicle.
Two Sum
O(n)
LeetCode
Pattern: Hash Table - Use hash map to store complements for O(n) lookup
Duplicate Integer
O(n)
NeetCode 150
Pattern: Hash Table / Set - Use a HashSet/Unordered Set to track seen numbers.
Sparse Arrays
O(N + M)
HackerRank
Pattern: Hash Table, Frequency Counter - Use a Hash Map to count input string frequencies in O(N), then lookup queries in O(1).
Max Element in Array
N/A
Smart Interviews
Pattern: Linear Traversal / Simple Scan - Initialize a variable to the smallest possible value and iterate through the array, updating the maximum value encountered.
The Missing Number
N/A
Custom
Pattern: Summation/XOR Logic - Use the arithmetic series formula (N*(N+1)/2) to find the expected sum, and subtract the actual sum of the array elements to find the missing number.
Odd and Even Sum
N/A
Custom
Pattern: Conditional Summation - Use a single linear pass to check each element's parity and accumulate separate sums for odd and even numbers.
Find Duplicate Number in Array
N/A
Smart Interviews
Pattern: Cycle Detection (Floyd's Tortoise and Hare) - Treat the array as a linked list where the index i points to the value nums[i]. A duplicate creates a cycle.
Number Distribution (Frequency Count)
N/A
Smart Interviews
Pattern: Frequency Counting / Hashing - Use a hash map to count the occurrences of each number. Then, iterate through the map to find the counts of required numbers.
Triangle Validator
N/A
Smart Interviews
Pattern: Geometry / Inequality Rule - Check the triangle inequality theorem: the sum of the lengths of any two sides of a triangle must be greater than the length of the third side.
Arithmetic Operators
N/A
Smart Interviews
Pattern: Conditional Logic / Switch - Read two numbers and a character operator. Use conditional logic (if/else or switch) to perform the correct operation.
Arithmetic Progression Check
N/A
Smart Interviews
Pattern: Sequence Check / Difference - Calculate the difference between the first two elements. Then, iterate through the rest of the array, checking if the difference between all consecutive pairs is constant.
Factorial
N/A
Smart Interviews
Pattern: Iteration / Recursion - Use an iterative loop starting from 1 up to N, multiplying the result at each step. Must handle data type overflow for large N.
Natural Numbers Sum
N/A
Smart Interviews
Pattern: Arithmetic Series Formula - Use Gauss's formula, $S = rac{N(N+1)}{2}$, to calculate the sum in constant time.
Matrix Row and Column Sums
O(N*M)
Smart Interviews
Pattern: Streaming Input / 1D Array Simulation - Calculate Row Sums by streaming and Column Sums using an auxiliary 1D array.
Lower Triangle Sum
N/A
Smart Interviews
Pattern: Index-based Traversal / Conditionals - Iterate through the matrix and only sum elements where the row index (i) is greater than or equal to the column index (j), i.e., i >= j.
Submatrix Sum
O(NΒ²)
Custom/Smart Interviews
Pattern: Range Query / 2D Prefix Sum (Optimized) - Brute force sum for small N (O(N^2)) or 2D Prefix Sum for optimization (O(1) query).
Filled and Hollow Rectangle
O(N*M)
Custom
Pattern: Basic Nested Loops - Use two nested loops (i for rows, j for columns). For Hollow, add a conditional check for boundaries.
Half Diamond Pattern
O(NΒ²)
Custom
Pattern: Symmetry Combination - Print the pattern in two halves: the increasing part (top) and the decreasing part (bottom).
Triangle and Pyramid Patterns
O(NΒ²)
Custom
Pattern: Row-Index Dependent Printing - Use the row index (i) to determine the number of characters or spaces to print in the inner loop.
Odd Even Index
N/A
Smart Interviews
Pattern: Index-based Conditional Traversal - Iterate through the string index and check the parity (i % 2) of the index to route the character to the odd or even result string.
Digit String Check
N/A
Smart Interviews
Pattern: Character Type Check - Iterate through the string and use a built-in character method (e.g., isdigit() or Character.isDigit()) to check if every character is a numerical digit.
Letter Coverage (Pangram Check)
N/A
Smart Interviews
Pattern: Boolean Array / Frequency Hashing - Use a fixed-size boolean array (size 26) to mark the presence of each letter (a-z) encountered during a single pass.
Vowels and Consonants
N/A
Smart Interviews
Pattern: Character Set Check - Use a predefined set (HashSet in Java/C++, set in Python) of vowels for fast O(1) lookups during a single string traversal.
Compress String (Run-Length Encoding)
N/A
Smart Interviews
Pattern: Run-Length Encoding / Two Pointers - Use a two-pointer approach (read pointer and write pointer) to count consecutive identical characters and replace the sequence with the character followed by the count.
Reverse Words in a String
N/A
LeetCode
Pattern: Word Traversal / Stack / Two Pointers - Split the string into words, then process the list of words in reverse order, ignoring extra spaces. Or, use two pointers to reverse each word in-place, then reverse the entire string.
Valid Palindrome (Alpha-Numeric Filter)
N/A
LeetCode
Pattern: Two Pointers / Filtering - Use two pointers (one at start, one at end). Move pointers inward, skipping non-alphanumeric characters. Compare the characters after converting them to the same case.
Roman to Integer
N/A
LeetCode
Pattern: Conditional Traversal / Hash Map Lookup - Iterate through the string from left to right. If the current symbol's value is less than the next symbol's value, subtract it; otherwise, add it.
First Unique Character in a String
N/A
LeetCode
Pattern: Two-Pass Hashing / Frequency Count - Use a two-pass approach: 1) Count frequencies in a Hash Map. 2) Iterate through the string again and return the index of the first character with a count of 1.
Integer to Roman
N/A
LeetCode
Pattern: Greedy Lookup / Paired Hash Map - Use a lookup table of Roman values and symbols, sorted from largest to smallest. Greedily subtract the largest possible value until the integer reaches zero.
Valid Parentheses
N/A
LeetCode
Pattern: Stack / Hash Map Lookup - Use a Stack to store opening brackets. Use a Hash Map for O(1) lookup to find the matching opener when a closing bracket is encountered.
Rotation of Matrix (90 Degrees Clockwise)
N/A
Smart Interviews
Pattern: In-Place Transpose & Reverse - To achieve a 90-degree clockwise rotation in-place, first transpose the matrix (swap A[i][j] with A[j][i]), and then reverse each row.
Diagonal Traversal of Matrix
N/A
Smart Interviews
Pattern: Index Grouping - Elements on the same anti-diagonal share the same sum of indices (i + j). Group elements by this sum and process the groups.
Spiral Traversal of Matrix
N/A
Smart Interviews
Pattern: Boundary Pointers - Use four pointers (top, bottom, left, right) to define boundaries. Iterate through the four sides, shifting the boundaries inward after each pass.
Count Digits and Reverse Number
N/A
TakeUForward
Pattern: Digit Traversal (Modulo/Division) - Use a while loop that continues while N > 0. Inside the loop, extract the last digit (N % 10) and update N (N /= 10).
Greatest Common Divisor (GCD/HCF)
N/A
TakeUForward
Pattern: Euclidean Algorithm - Use the efficient Euclidean Algorithm, which relies on the property: GCD(a, b) = GCD(b, a % b).
Check Palindrome and Armstrong Number
N/A
TakeUForward
Pattern: Digit Reversal and Power Summation - Both require reversing the digits. For Palindrome, check if the original number equals the reversed number. For Armstrong, check if the original number equals the sum of its digits raised to the power of the total digit count.
Subsets (Backtracking)
N/A
LeetCode
Pattern: Backtracking / DFS - Use a recursive function to explore all possibilities. At each element, make a choice: 1) Include the element and recurse. 2) Exclude the element and recurse. Backtrack by removing the element.
Permutations (Backtracking)
N/A
LeetCode
Pattern: Backtracking / State Management - Use a recursive function. At each step, iterate through the elements not yet included in the current permutation. This requires tracking the state of which numbers are used.
Power of Two
N/A
LeetCode
Pattern: Bit-Manipulation (Masking) - A positive integer N is a power of two if and only if N has exactly one bit set to 1. The bitwise trick N & (N - 1) clears the rightmost set bit.
Single Number
N/A
LeetCode
Pattern: Bit-Manipulation (XOR) - Utilize the XOR property A ^ A = 0 and A ^ 0 = A. XORing all elements in the array will cancel out all paired numbers, leaving only the unique single number.