Visualizations
88 visualizations
array
6Delete from Given Index
Remove the element at a given index by shifting all subsequent elements one position to the left.
Deletion in Array
Remove the last element from the array, decreasing its size by one.
Insert at given index
Insert a new element at a given index by shifting all subsequent elements one position to the right.
Insertion
Add a new element at the end of the array, increasing its size by one.
Reverse an array
Reverse the order of all elements in the array using the two-pointer technique, swapping from both ends inward.
Traversal in Array
Visit each element of the array one by one from start to end, accessing every index exactly once.
two-pointers
6Two Pointers
Uses left and right indices moving toward each other to solve pair-sum and partitioning problems in O(n).
Two Sum II
Finds two indices in a sorted array that sum to a target using opposite-end two pointers; O(n) time, O(1) space.
3 Sum
Finds all unique triplets summing to zero by sorting and applying two pointers for each fixed element; O(n²).
Sort Colors
Sorts an array of 0s, 1s, and 2s in one pass using Dijkstra's Dutch National Flag three-pointer algorithm.
Container With Most Water
Finds two lines forming the largest water container using two pointers that always move the shorter line inward.
Move Zeroes to End
Moves all zeros to the end while preserving relative order of non-zero elements in-place; O(n) time, O(1) space.
sliding-window
4Max Sum Subarray of Size K
Finds the maximum sum of any k consecutive elements using a fixed-size sliding window in O(n).
Sliding Window
Maintains a moving subarray window and slides it to avoid recomputing overlapping regions; O(n).
Max Consecutive Bit
Counts the longest run of consecutive 1s in a binary array by resetting a counter on each 0; O(n).
Maximize Number of 1's
Finds the maximum consecutive 1s achievable by flipping at most k zeros using a variable sliding window; O(n).
prefix-sum
3Prefix Sum
Preprocesses cumulative sums so any range sum query can be answered in O(1) after O(n) build time.
Subarray Sum Equals K
Counts subarrays with sum exactly equal to k using prefix sums and a HashMap; O(n) time and space.
Matrix Block Sum (2D Prefix Sum)
Computes block sums for every cell in a matrix using 2D prefix sums and the inclusion-exclusion formula; O(m×n).
kadane-s-algorithm
3Kadane's Algorithm
Finds the maximum sum contiguous subarray in O(n) by deciding at each step whether to extend or restart.
Max Circular Subarray Sum
You are given a circular array arr[] of integers, find the maximum possible sum of a non-empty subarray. In a circular array, the subarray can start at the end and wrap around to the beginning. Return the maximum non-empty subarray sum, considering both non-wrapping and wrapping cases.
Maximum Product Subarray
Finds the maximum product subarray by tracking both max and min products to handle negative flips; O(n).
strings
1String Basic Operations
Covers core string primitives — access, concat, substring, search, and split — with their complexity tradeoffs.
two-pointers-palindrom
5Reverse a String
Swaps characters from both ends toward the middle using two pointers; O(n) time, O(1) space.
Valid Palindrome
Verifies a string reads the same forwards and backwards using the two-pointer technique.
Valid Palindrome II
Checks if a string is a palindrome while skipping spaces using two pointers.
Length of the longest substring
Finds the longest substring with no repeating characters using a sliding window and hash set; O(n).
Palindrome Substrings
Counts all palindromic substrings by expanding around each center; O(n²) time, O(1) space.
sliding-window-strings
2Count Occurrences of Anagrams
Counts all anagram occurrences of a pattern in a string using a fixed-size sliding window; O(n).
Longest Nice Substring
Finds the longest substring where every letter appears in both cases using divide-and-conquer.
binary-search
6Binary Search
Eliminates half the search space each step on a sorted array; O(log n).
Peak Element
Finds any element strictly greater than its neighbors using binary search; O(log n) even on unsorted arrays.
Square Root (x)
Finds the integer floor of √n without built-in functions using binary search on the answer space.
Search Insert Position
Returns the index where a target exists or should be inserted in a sorted array; the lower-bound binary search.
Search in a Rotated Sorted Array
Searches a rotated sorted array in O(log n) by determining which half is still sorted at each step.
Find Minimum in Rotated Sorted Array
Finds the minimum element in a rotated sorted array in O(log n) by comparing mid with the right boundary.
lower-upper-bound
2Ceil the Floor
Finds both floor and ceil of a target in a single binary search pass over a sorted array.
Floor in a Sorted Array
Finds the largest element ≤ target in a sorted array using binary search with a "last valid" tracker.
stack
1Stack
Last-In-First-Out structure with O(1) push, pop, and peek; backbone of DFS, expression evaluation, and undo.
monotonic-stack
6Asteroid Collision
Simulates asteroid collisions where larger survive, using a stack to process each asteroid in O(n).
Daily Temperatures
Returns the number of days until a warmer temperature for each day using a monotonic decreasing stack; O(n).
Largest Rectangle in Histogram
Finds the maximum rectangle area in a histogram using a monotonic increasing stack; O(n) time.
Next Greater Element
Finds the next greater element to the right for each array element using a monotonic decreasing stack; O(n).
Next Greater Element II
Finds next greater elements in a circular array by iterating twice with modulo and a monotonic stack; O(n).
Online Stock Span
Computes how many consecutive prior days had a price ≤ today using a monotonic stack with accumulated spans; O(1) amortized.
expression-evaluation
4Infix to Postfix
Converts infix expressions to Reverse Polish Notation using Dijkstra's Shunting-Yard algorithm; O(n).
Infix to Prefix
Converts standard infix expressions to prefix (Polish) notation using reversal and the Shunting-Yard algorithm.
Postfix to Infix
Converts postfix to infix by wrapping each operator application in parentheses using a stack; O(n).
Postfix to Prefix
Converts postfix to prefix by pushing operands and combining on operators using a stack; O(n).
stack-simulation
2Backspace String Compare
Simulates backspace characters and compares two strings using two pointers from the end; O(n) time, O(1) space.
Remove Adjacent Duplicates
Removes all adjacent duplicate characters repeatedly using a stack; O(n) time and space.
linked-list
1Linked List
A chain of nodes each holding a value and a pointer to the next; O(1) head insert, O(n) search.
fast-and-slow-pointers
4Detect Loop in Linked List
Detects a cycle in a linked list using Floyd's fast-slow pointer algorithm; O(n) time, O(1) space.
Linked L:ist cycle ||
Finds the node where a cycle begins by resetting one pointer to head after detection; O(n) time, O(1) space.
Middle of Linked List
Finds the middle node of a linked list in one pass using fast (×2) and slow (×1) pointers.
Remove Nth Node From End
Removes the Nth node from the end of a linked list in one pass using a gap-of-N two-pointer technique.
reversal-pattern
4Palindrome Linked List
Checks if a linked list is a palindrome by finding the middle, reversing the second half, and comparing.
Reverse Linked List
Reverses a singly linked list in-place by relinking pointers; O(n) time, O(1) space.
Reverse Linked List II
Reverses only a sublist from position left to right in-place using the head-insertion trick; O(n).
Rotate List
Rotates a linked list right by k places by making it circular and cutting at the new tail; O(n).
merge-sort
3Merge Two Sorted Lists
Merges two sorted linked lists into one sorted list by comparing nodes with a dummy head; O(n+m).
Remove Duplicates from Sorted List
Removes consecutive duplicate nodes from a sorted linked list in-place; O(n) time, O(1) space.
Sort List
Sorts a linked list using Merge Sort — find middle, split, sort halves, merge; O(n log n) time, O(log n) space.
doubly-linked-list
2LRU Cache
Evicts the least recently used item in O(1) using a HashMap combined with a doubly linked list.
Reverse a Doubly Linked List
Reverses a doubly linked list by swapping prev and next pointers for every node; O(n) time, O(1) space.
merge-sort-reorder
1Flatten Multilevel Doubly Linked List
hashmap
2Majority Element
Top K Frequent Elements
Given a non-empty integer array arr[]. Your task is to find and return the top k elements which have the highest frequency in the array.
divide-conquer
1Divide and Conquer
Splits a problem into halves, solves each recursively, and combines results — basis of Merge Sort and Binary Search.
tree
3Inorder Traversal
An inorder traversal first visits the left child (including its entire subtree), then visits the node, and finally visits the right child (including its entire subtree).
Postorder Traversal
A postorder traversal first visits the left child (including its entire subtree), then visits the right child (including its entire subtree), and finally visits the node itself.
Preorder Traversal
A preorder traversal first visits the node, then visits the left child (including its entire subtree), and finally visits the right child (including its entire subtree).
bst
1Binary Search Tree (BST)
Ordered binary tree where left < node < right; O(log n) average search, insert, and delete.
graph
2Breadth First Search
Depth First Search
greedy
1Sorting Local Choice
Sort array or select elements to make locally optimal choice and achieve global optimum.
sorting
9Bubble Sort
Repeatedly swaps adjacent elements until the array is sorted — simple, O(n²), good for teaching.
Selection Sort
Finds the minimum unsorted element and places it at the correct position; always O(n²) comparisons.
Insertion Sort
Builds a sorted array one element at a time by inserting each into its correct position; O(n) on nearly-sorted input.
Merge Sort
Divides the array in half, sorts each half, then merges — guaranteed O(n log n) and stable.
Quick Sort
Picks a pivot, partitions around it, and recursively sorts each side; O(n log n) average, in-place.
Heap Sort
Sorting using binary heap data structure
Counting Sort
Non-comparison sort using counting
Radix Sort
Sort by processing individual digits
Bucket Sort
Distribute elements into buckets and sort
search
1Linear Search
Scans every element one by one; works on any array but O(n) in the worst case.
linear
2Queue
First-In-First-Out structure with O(1) enqueue and dequeue; backbone of BFS and task scheduling.
Doubly Linked List
Each node holds prev and next pointers enabling O(1) deletion at any known node and backward traversal.