Data Structures & Algorithms
Complete catalog of 99 interactive algorithm visualizers. Browse by data structure category or filter by difficulty.
An n x n matrix is valid if every row and every column contains all the integers from 1 to n (inclusive). Check validity using row and column hash sets.
Given an integer array nums of length n, create and return an array ans of length 2n where ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n.
Find two lines that together with the x-axis form a container containing the most water using an optimal O(n) two-pointer inward scan.
Detect duplicate elements in an array using an instant-lookup hash set.
Design a HashSet without using any built-in hash table libraries, demonstrating hashing (key % size) and collision resolution via separate chaining in dynamic buckets.
Sort an array of 0s, 1s, and 2s in-place in linear time using Dijkstra's 3-way partitioning Dutch National Flag algorithm.
Group strings together using sorted character keys in a hash map.
Check if two strings contain identical character frequency distributions.
Find length of longest contiguous integer streak in O(n) using a hash set.
Sort an array of integers in ascending order using divide-and-conquer Merge Sort with O(n log n) time complexity.
Merge two sorted integer arrays into nums1 as one sorted array using two pointers and an auxiliary merge buffer.
Merge characters from word1 and word2 in alternating order, appending any remaining suffix characters.
Move all zeros in an array to the end in-place while maintaining the relative order of the non-zero elements using two pointers.
Precompute a 2D prefix sum matrix in O(m · n) time to evaluate any submatrix sum query in O(1) time using the 2D Inclusion-Exclusion Principle.
Precompute prefix sums in O(n) to evaluate contiguous subarray sum queries in constant O(1) time.
Square numbers and sort in O(n) time using opposing two pointers.
Find all unique triplets that sum to zero with sorting and two pointers.
Find indices of two numbers that add up to target using a single-pass hash map.
Find two numbers in a 1-indexed sorted array that add up to a target number using opposing two pointers in O(n) time and O(1) space.
Determine if a string can be a palindrome after deleting at most one character using two pointers.
Validate a 9x9 Sudoku board checking rows, columns, and 3x3 subgrids.
