# Rulcode - Master Algorithms Visually > Rulcode is an interactive, open-source educational platform designed to help developers master Data Structures and Algorithms (DSA). We provide visual animations, detailed explanations, and code snippets in multiple languages (Python, Java, C++, TypeScript) for over 200 coding interview problems. ## Algorithm Directory Below is a categorized list of all our published algorithm visualizations and solutions. ### Bit Manipulation, 1-D Dynamic Programming - [Counting Bits](https://rulcode.com/problem/counting-bits): Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1's in the binary representation o... ### Bit Manipulation, Divide and Conquer - [Number of 1 Bits](https://rulcode.com/problem/number-of-1-bits): Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). Example 1: Input: n = 0... ### Bit Manipulation, Divide Conquer - [Reverse Bits](https://rulcode.com/problem/reverse-bits): Reverse bits of a given 32 bits unsigned integer and return the resulting unsigned integer. Example 1: Input: n = 00000010100101000001111010011100 Ou... ### Bit Manipulation, Math - [Sum of Two Integers](https://rulcode.com/problem/sum-of-two-integers): Given two integers a and b, return the sum of the two integers without using the operators + and -. Example 1: Input: a = 1, b = 2 Output: 3 Example... ### Bit Manipulation, Math, Sorting, Binary Search, Hash Table - [Missing Number](https://rulcode.com/problem/missing-number): Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array. Example 1:... ### Advanced Algorithm - [Tarjan's Algorithm](https://rulcode.com/problem/tarjans): Find strongly connected components - [Fenwick Tree (BIT)](https://rulcode.com/problem/fenwick-tree): Binary indexed tree for prefix sums - [Segment Tree](https://rulcode.com/problem/segment-tree): Range query data structure - [Sparse Table](https://rulcode.com/problem/sparse-table): Range minimum query in O(1) - [Union by Rank + Path Compression](https://rulcode.com/problem/union-by-rank): Optimized union-find - [Binary Lifting](https://rulcode.com/problem/binary-lifting): LCA using binary lifting - [Manacher's Algorithm](https://rulcode.com/problem/manachers): Longest palindromic substring - [Rabin-Karp](https://rulcode.com/problem/rabin-karp): Rolling hash pattern matching - [KMP String Matching](https://rulcode.com/problem/kmp): Linear time pattern matching - [LRU Cache](https://rulcode.com/problem/lru-cache): Least Recently Used cache implementation using HashMap and Doubly Linked List ### Array - [Concatenation of Array](https://rulcode.com/problem/concatenation-of-array): Create a new array by concatenating two copies of a given integer array. ### Array, 1-D Dynamic Programming - [Maximum Product Subarray](https://rulcode.com/problem/maximum-product-subarray): Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are generated so that the answer wi... ### Array, Backtracking - [Combination Sum II](https://rulcode.com/problem/combination-sum-ii): Find all unique combinations in candidates where the candidate numbers sum to target, using each number only once. ### Array, Backtracking, Bit Manipulation - [Subsets II](https://rulcode.com/problem/subsets-ii): Given an integer array nums that may contain duplicates, return all possible subsets (the power set) without duplicate subsets. ### Array, Backtracking, Dynamic Programming - [Target Sum Ways](https://rulcode.com/problem/target-sum-ways): Find the number of ways to assign '+' or '-' to each number in an array such that the sum equals the target. ### Array, Binary Search - [Find Minimum in Rotated Sorted Array](https://rulcode.com/problem/find-minimum-in-rotated-sorted-array): Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become: ... - [Koko Eating Bananas](https://rulcode.com/problem/koko-eating-bananas): Find the minimum eating speed 'k' for Koko to finish all banana piles within 'h' hours. - [Search in Rotated Sorted Array](https://rulcode.com/problem/search-in-rotated-sorted-array): There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your function, nums is possibly rotated at ... ### Array, Binary Search, DFS, BFS, Union Find, Heap / Priority Queue - [Swim in Rising Water](https://rulcode.com/problem/swim-in-rising-water): Find the minimum time 't' to swim from top-left to bottom-right in an elevation grid, where you can swim between adjacent cells if both have elevation... ### Array, Binary Search, Sorting, Heap / Priority Queue - [Minimum Interval to Include Each Query](https://rulcode.com/problem/minimum-interval-to-include-each-query): Find the smallest interval size that contains each given query point, or -1 if none exists. ### Array, Bit Manipulation - [Single Number](https://rulcode.com/problem/single-number): Find the unique element in an array where all other elements appear twice. ### Array, Design Pattern, Matrix, Prefix Sum - [Range Sum Query 2D - Immutable](https://rulcode.com/problem/range-sum-query-2d-immutable): Design a data structure that supports O(1) time complexity for range sum queries on a 2D matrix after an O(m*n) preprocessing step. ### Array, DFS, BFS, Union Find, Matrix - [Surrounded Regions](https://rulcode.com/problem/surrounded-regions): Capture regions of 'O's that are entirely surrounded by 'X's, replacing them with 'X's. - [Max Area of Island](https://rulcode.com/problem/max-area-of-island): Find the maximum area of a 4-directionally connected island of 1s in a binary grid. ### Array, Divide and Conquer, 1-D Dynamic Programming - [Maximum Subarray](https://rulcode.com/problem/maximum-subarray): Given an integer array nums, find the subarray with the largest sum, and return its sum. A subarray is a contiguous non-empty sequence of elements wi... ### Array, Dynamic Programming - [Burst Balloons](https://rulcode.com/problem/burst-balloons): Maximize coins by bursting balloons in an optimal order. - [Min Cost Climbing Stairs](https://rulcode.com/problem/min-cost-climbing-stairs): Calculate the minimum cost to reach the top of a staircase, starting from either step 0 or step 1, with options to climb one or two steps. - [Coin Change II](https://rulcode.com/problem/coin-change-ii): Find the number of combinations to make up an amount using given coins. - [Best Time to Buy and Sell Stock with Cooldown](https://rulcode.com/problem/best-time-to-buy-and-sell-stock-with-cooldown): Find the maximum profit by buying and selling stock with a cooldown period. - [Partition Equal Subset Sum](https://rulcode.com/problem/partition-equal-subset-sum): Checks if an array can be partitioned into two subsets with equal sums. ### Array, Greedy - [Best Time to Buy and Sell Stock](https://rulcode.com/problem/best-time-to-buy-and-sell-stock): You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day... - [Merge Triplets to Form Target Triplet](https://rulcode.com/problem/merge-triplets-to-form-target-triplet): Determine if a target triplet can be formed by repeatedly merging other triplets using a max-component operation, discarding invalid triplets. ### Array, Greedy, Sorting, Hash Table - [Hand of Straights](https://rulcode.com/problem/hand-of-straights): Check if a hand of cards can be rearranged into groups of consecutive cards of a specified size. ### Array, Hash Table - [First Missing Positive](https://rulcode.com/problem/first-missing-positive): Given an unsorted integer array, find the smallest positive integer not present in it in O(n) time and O(1) space. - [Two Sum ](https://rulcode.com/problem/two-sum): Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each in... - [Jump Game II](https://rulcode.com/problem/jump-game-ii): Find the minimum number of jumps to reach the last index of an array, where each element represents the maximum jump length from that position. ### Array, Hash Table, Design Pattern, Data Stream - [Detect Squares](https://rulcode.com/problem/detect-squares): Design a data structure that allows adding points and efficiently counting axis-aligned squares formed with a query point and three existing points. ### Array, Hash Table, Divide and Conquer, Sorting - [Majority Element](https://rulcode.com/problem/majority-element): Find the element that appears more than ⌊n / 2⌋ times in an array of size n. ### Array, Hash Table, Prefix Sum - [Subarray Sum Equals K](https://rulcode.com/problem/subarray-sum-equals-k): Find the total number of contiguous subarrays whose sum equals a given integer k. ### Array, Hash Table, Sorting - [Contains Duplicate](https://rulcode.com/problem/contains-duplicate): Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. Example 1: ... - [Majority Element II](https://rulcode.com/problem/majority-element-ii): Find all elements in an integer array that appear more than ⌊n / 3⌋ times. ### Array, Hash Table, Sorting, Greedy, Heap / Priority Queue - [Task Scheduler](https://rulcode.com/problem/task-scheduler): Given CPU tasks and a cooling interval n, find the minimum number of CPU intervals to complete all tasks. ### Array, Hash Table, Two Pointers - [Two Pointers](https://rulcode.com/problem/two-pointers): Use two pointers to traverse arrays efficiently ### Array, Hash Table, Union Find - [Longest Consecutive Sequence](https://rulcode.com/problem/longest-consecutive-sequence): Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n... ### Array, Heap / Priority Queue - [Last Stone Weight](https://rulcode.com/problem/last-stone-weight): Find the weight of the last remaining stone after repeatedly smashing the two heaviest stones together. ### Array, Math & Geometry - [Plus One](https://rulcode.com/problem/plus-one): Given a large integer represented as an array of digits, increment it by one and return the resulting array. ### Array, Math & Geometry, Stack - [Evaluate Reverse Polish Notation](https://rulcode.com/problem/evaluate-reverse-polish-notation): Evaluate an arithmetic expression given in Reverse Polish Notation (RPN) using a stack. ### Array, Math, Simulation - [Spiral Matrix](https://rulcode.com/problem/spiral-matrix): Given an m × n matrix, return all elements of the matrix in spiral order. Example: Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4... ### Array, Matrix, BFS - [Rotting Oranges](https://rulcode.com/problem/rotting-oranges): Calculate the minimum time for all fresh oranges to rot in a grid using BFS. ### Array, Prefix Sum - [Find the Highest Altitude](https://rulcode.com/problem/find-the-highest-altitude): Calculate the maximum altitude reached by a biker given a sequence of altitude gains between points. - [Product of Array Except Self](https://rulcode.com/problem/product-of-array-except-self): Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements of nums except nums[i]. The produ... ### Array, Sorting, Geomentry, Heap / Priority Queue, Divide and Conquer, Math, Quickselect - [K Closest Points to Origin](https://rulcode.com/problem/k-closest-points-to-origin): Find the k closest points to the origin in a given set of points. ### Array, Sorting, Interval - [Merge Intervals](https://rulcode.com/problem/merge-intervals): Merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input. ### Array, Sorting, Intervals - [Meeting Rooms](https://rulcode.com/problem/meeting-rooms): Determine if a person could attend all meetings given a list of meeting time intervals. ### Array, Stack - [Asteroid Collision](https://rulcode.com/problem/asteroid-collision): Simulate collisions between asteroids moving left and right, determining the final state. ### Array, Stack, Monotonic Stack - [Daily Temperatures](https://rulcode.com/problem/daily-temperatures): Given daily temperatures, return an array indicating how many days to wait for a warmer temperature. ### Array, Stack, Simulation - [Baseball Game](https://rulcode.com/problem/baseball-game): Calculate the total score of a baseball game given a list of operations that modify a score record. ### Array, String - [Longest Common Prefix](https://rulcode.com/problem/longest-common-prefix): Finds the longest common prefix among an array of strings. - [Kadane's Algorithm](https://rulcode.com/problem/kadanes-algorithm): Find maximum subarray sum efficiently - [Cyclic Sort](https://rulcode.com/problem/cyclic-sort): Sort by placing elements at their correct index - [Dutch National Flag](https://rulcode.com/problem/dutch-national-flag): Sort array of three distinct elements - [Rotate Array In-Place](https://rulcode.com/problem/rotate-array): Rotate array elements without extra space ### Array, String, Binary Search - [Binary Search](https://rulcode.com/problem/binary-search): Search in sorted arrays in logarithmic time ### Array, String, Design Pattern - [Encode and Decode Strings ](https://rulcode.com/problem/encode-and-decode-strings): Design an algorithm to encode a list of strings to a single string. The encoded string is sent over the network and should be decoded back to the orig... ### Array, String, Graphs, Sorting, Heap / Priority Queue - [Reconstruct Itinerary](https://rulcode.com/problem/reconstruct-itinerary): Reconstruct an itinerary from a list of airline tickets, starting from "JFK", visiting all airports once, and returning the lexicographically smallest... ### Array, String, Prefix Sum - [Prefix Sum](https://rulcode.com/problem/prefix-sum): Pre-compute cumulative sums for range queries ### Array, String, Sliding Window - [Sliding Window](https://rulcode.com/problem/sliding-window): Maintain a window of elements for efficient computation ### Array, Two Pointers - [Remove Duplicates from Sorted Array](https://rulcode.com/problem/remove-duplicates-from-sorted-array): Given a sorted array, remove duplicates in-place such that each unique element appears only once. Return the number of unique elements. ### Array, Two Pointers, Greedy - [Container With Most Water](https://rulcode.com/problem/container-with-most-water): You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, hei... ### Array, Two Pointers, Sorting - [3Sum](https://rulcode.com/problem/3sum): Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k]... - [4Sum](https://rulcode.com/problem/4Sum): Find all unique quadruplets in a given array that sum up to a specific target. ### Array, Two Pointers, Sorting, Greedy - [Boats to Save People](https://rulcode.com/problem/boats-to-save-people): Find the minimum number of boats required to carry all people, given weight limits and boat capacity. ### Backtracking - [Sudoku Solver](https://rulcode.com/problem/sudoku-solver): Solve Sudoku puzzle - [Combinations](https://rulcode.com/problem/combinations): Generate all k-combinations - [Subsets](https://rulcode.com/problem/subsets): Generate all subsets of a set - [Word Search](https://rulcode.com/problem/word-search-grid): Find word in 2D grid - [Permutations](https://rulcode.com/problem/permutations): Generate all permutations ### Backtracking, Array - [N-Queens](https://rulcode.com/problem/n-queens): Place N queens on N×N board ### Backtracking, Dynamic Programming - [Generate Parentheses](https://rulcode.com/problem/generate-parentheses): Generates all combinations of well-formed parentheses for a given number 'n'. ### Backtracking, String - [Regular Expression Matching](https://rulcode.com/problem/regular-expression-matching): Implement regular expression matching with support for '.' and '*'. ### Binary Search, Array, Divide and Conquer - [Median Of Two Sorted Arrays](https://rulcode.com/problem/median-of-two-sorted-arrays): Find the median of two sorted arrays with O(log(m+n)) runtime complexity. ### Binary Search, Matrix - [Search a 2D Matrix](https://rulcode.com/problem/search-a-2d-matrix): Efficiently search for a target value in an m x n matrix with sorted rows and increasing first elements. ### Binary Search, Sliding Window, Prefix Sum - [Minimum Size Subarray Sum](https://rulcode.com/problem/minimum-size-subarray-sum): Find the minimal length of a contiguous subarray whose sum is greater than or equal to a given target. ### Binary Search, String, Hash Table - [Time Based Key-Value Store](https://rulcode.com/problem/time-based-key-value-store): Design a time-based key-value data structure that stores multiple values for the same key at different timestamps and retrieves the key's value at a c... ### Bit Manipulation - [Count Bits](https://rulcode.com/problem/count-bits): Brian Kernighan's algorithm - [XOR Trick](https://rulcode.com/problem/xor-trick): Find single number using XOR - [Subset Generation with Bits](https://rulcode.com/problem/subset-generation-bits): Generate subsets using bitmasks ### Design Pattern, Heap / Priority Queue - [Design Twitter](https://rulcode.com/problem/design-twitter): Design a simplified version of Twitter. ### Design Pattern, Stack - [ Implement Stack using Queues](https://rulcode.com/problem/implement-stack-using-queues): Implement a LIFO stack using only standard FIFO queue operations. ### Dynamic Programming - [Edit Distance](https://rulcode.com/problem/edit-distance): Minimum edits to transform strings - [Partition Equal Subset](https://rulcode.com/problem/partition-equal-subset): Check if array can be partitioned equally - [Longest Common Subsequence](https://rulcode.com/problem/lcs): Find longest common subsequence - [Combination Sum](https://rulcode.com/problem/combination-sum): Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of candidates where the chosen nu... - [Longest Increasing Subsequence](https://rulcode.com/problem/lis): Find LIS in array - [0/1 Knapsack ](https://rulcode.com/problem/knapsack-01): Maximize value with weight constraint - [House Robber II](https://rulcode.com/problem/house-robber-ii): All houses are arranged in a circle. That means the first house is the neighbor of the last one. Adjacent houses cannot both be robbed. Given an inte... - [Matrix Path DP](https://rulcode.com/problem/matrix-path-dp): Find unique or minimum paths in matrix ### Dynamic Programming, Array - [House Robber](https://rulcode.com/problem/house-robber): You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. Adjacent houses have security s... ### Dynamic Programming, Array, BFS - [Coin Change](https://rulcode.com/problem/coin-change): You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return ... ### Dynamic Programming, Array, Binary Search - [Longest Increasing Subsequence](https://rulcode.com/problem/longest-increasing-subsequence): Given an integer array nums, return the length of the longest strictly increasing subsequence. Example 1: Input: nums = [10,9,2,5,3,7,101,18] Output:... ### Dynamic Programming, Array, Greedy - [Jump Game](https://rulcode.com/problem/jump-game): You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum ju... ### Dynamic Programming, Array, Hash Table, String, Trie, Memorization - [Word Break Problem](https://rulcode.com/problem/word-break-problem): Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary wor... ### Dynamic Programming, Array, String, 1-D Dynamic Programming, Trie, Memorization - [Word Break](https://rulcode.com/problem/word-break): Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated sequence of one or more dictionary wor... ### Dynamic Programming, DFS, BFS, Graphs, Topological Sort, Memoization, matrix - [Longest Increasing Path in a Matrix](https://rulcode.com/problem/longest-increasing-path-in-a-matrix): Find the longest path in a matrix where each step moves to an adjacent cell with a strictly greater value. ### Dynamic Programming, Greedy, Array - [Best Time to Buy and Sell Stock II](https://rulcode.com/problem/best-time-to-buy-and-sell-stock-ii): Find the maximum profit by buying and selling a stock multiple times, holding at most one share at any given time. ### Dynamic Programming, Math, Combinatorics - [Unique Paths](https://rulcode.com/problem/unique-paths): There is a robot on an m × n grid. The robot is initially located at the top-left corner (0, 0). The robot tries to move to the bottom-right corner (m... ### Dynamic Programming, Math, Memorization - [Climbing Stairs](https://rulcode.com/problem/climbing-stairs): You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb ... ### Dynamic Programming, String - [Decode Ways](https://rulcode.com/problem/decode-ways): A message containing letters from A–Z can be encoded into numbers using the mapping 'A' -> "1", 'B' -> "2", ..., 'Z' -> "26". Given a string s contai... - [Longest Common Subsequence](https://rulcode.com/problem/longest-common-subsequence): Given two strings text1 and text2, return the length of their longest common subsequence. A subsequence is a sequence that appears in the same relativ... ### Graph - [Floyd-Warshall](https://rulcode.com/problem/floyd-warshall): All-pairs shortest paths - [Kruskal's Algorithm | Min Cost ](https://rulcode.com/problem/kruskals): Find minimum spanning tree - [Prim's Algorithm](https://rulcode.com/problem/prims): Find MST using greedy approach - [A* Search](https://rulcode.com/problem/a-star): Heuristic pathfinding algorithm - [Graph BFS](https://rulcode.com/problem/graph-bfs): Breadth-first traversal of graphs - [Topological Sort](https://rulcode.com/problem/topological-sort): Kahn's algorithm for DAG ordering - [Graph DFS](https://rulcode.com/problem/graph-dfs): Depth-first traversal of graphs - [Union-Find](https://rulcode.com/problem/union-find): Disjoint set data structure ### Graph, Array, BFS, Matrix, DFS - [Pacific Atlantic Water Flow](https://rulcode.com/problem/pacific-atlantic-water-flow): There is an m × n rectangular grid heights where heights[r][c] represents the height above sea level of the cell at coordinate (r, c). The island touc... ### Graph, Array, DFS, BFS, Union Find, Matrix - [Number of Connected Components in an Undirected Graph](https://rulcode.com/problem/number-of-connected-components-in-an-undirected-graph): You have a graph of n nodes. You are given an integer n and an array edges where edges[i] = [ai, bi] indicates that there is an edge between ai and bi... - [Number of Islands](https://rulcode.com/problem/number-of-islands): Given an m × n 2D binary grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water a... ### Graph, Array, String, DFS, Topological Sort, BFS - [Alien Dictionary](https://rulcode.com/problem/alien-dictionary): There is a new alien language that uses the English alphabet. However, the order among the letters is unknown to you. You are given a list of strings... ### Graph, BFS, DFS, Union Find - [Graph Valid Tree](https://rulcode.com/problem/graph-valid-tree): You have a graph of n nodes labeled from 0 to n - 1. You are given an integer n and a list of edges where edges[i] = [ai, bi] indicates that there is ... ### Graph, DFS, BFS, Heap / Priority Queue - [Dijkstra's Algorithm](https://rulcode.com/problem/dijkstras): Single-source shortest path ### Graph, DFS, BFS, Topological Sort - [Course Schedule](https://rulcode.com/problem/course-schedule): Determine if it is possible to finish all courses given prerequisites. ### Graph, Hash Table, DFS, BFS - [Clone Graph](https://rulcode.com/problem/clone-graph): Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph. Each node in the graph contains a value and a li... ### Graph, Heap / Priority Queue, Dynamic Programming, DFS, BFS - [Bellman-Ford | Cheapest Flight](https://rulcode.com/problem/bellman-ford): Shortest path with negative weights ### Graphs, DFS, BFS - [Course Schedule II](https://rulcode.com/problem/course-schedule-ii): Find a valid ordering of courses to take, respecting prerequisites, or return an empty array if a cycle exists. ### Graphs, DFS, BFS, Union Find - [Redundant Connection](https://rulcode.com/problem/redundant-connection): Finds the last edge in a given graph that forms a cycle, resulting in a tree if removed. ### Greedy - [Huffman Encoding](https://rulcode.com/problem/huffman-encoding): Optimal prefix-free encoding - [Activity Selection](https://rulcode.com/problem/activity-selection): Given an array of intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the int... - [Gas Station](https://rulcode.com/problem/gas-station): Find starting station for circular tour - [Interval Scheduling](https://rulcode.com/problem/interval-scheduling): You are given an array of non-overlapping intervals where intervals[i] = [starti, endi] represent the start and the end of the i-th interval and inter... ### Hash Table, Greedy, String, Two Pointers - [Partition Labels](https://rulcode.com/problem/partition-labels): Partition a string into the maximum number of parts such that each letter appears in at most one part. ### Hash Table, Sliding Window - [Contains Duplicate II](https://rulcode.com/problem/contains-duplicate-ii): Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(... ### Hash Table, Two Pointers, String, Sliding Window - [Permutation in String](https://rulcode.com/problem/permutation-in-string): Checks if a permutation of string s1 exists as a substring in string s2 using a sliding window approach. ### Heap / Priority Queue, Array, Hash Table, Sorting, Bucket Sort, Divide and Conquer, Quickselect - [Top K Frequent Elements](https://rulcode.com/problem/top-k-frequent-elements): Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any order. Example 1: Input: nums = [... ### Heap / Priority Queue, Array, Sliding Window, Monotonic Queue - [Sliding Window Maximum](https://rulcode.com/problem/sliding-window-maximum): Find max in each window ### Heap / Priority Queue, Array, Sorting, Divide and Conquer, Quickselect - [Kth Largest Element](https://rulcode.com/problem/kth-largest): Find kth largest using min heap ### Interval, Array - [Insert Interval](https://rulcode.com/problem/insert-interval): You are given an array of non-overlapping intervals where intervals[i] = [starti, endi] represent the start and the end of the i-th interval and inter... ### Interval, Array, Two Pointers, Greedy, Sorting, Heap / Priority Queue, Prefix Sum - [Meeting Rooms II](https://rulcode.com/problem/meeting-rooms-ii): Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required. Examp... ### Interval, Sorting, Greedy, Dynamic Programming, Array - [Non-overlapping Intervals](https://rulcode.com/problem/non-overlapping-intervals): Given an array of intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the int... ### Linked List - [Merge K Sorted Lists](https://rulcode.com/problem/merge-k-lists): Merge using min heap - [Middle Node](https://rulcode.com/problem/middle-node): Find middle node using fast and slow pointers - [Merge Two Sorted Lists](https://rulcode.com/problem/merge-sorted-lists): Merge two sorted linked lists - [Fast & Slow Pointers](https://rulcode.com/problem/fast-slow-pointers): Detect cycles and find middle using two pointers - [Reverse Linked List II](https://rulcode.com/problem/reverse-linked-list-ii): Reverses a sub-portion of a singly linked list between specified left and right positions (1-indexed). ### Linked List, Divide and Conquer, Heap / Priority Queue, Merg Sort - [Merge K Sorted Lists](https://rulcode.com/problem/merge-k-sorted-lists): You are given an array of k sorted linked-lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list... ### Linked List, Hash Table, Two Pointers - [Detect Cycle in a Linked List](https://rulcode.com/problem/detect-cycle-in-a-linked-list): Given head, the head of a linked list, determine if the linked list has a cycle in it. There is a cycle in a linked list if there is some node in the ... ### Linked List, Math & Geometry, Recursion - [Add Two Numbers](https://rulcode.com/problem/add-two-numbers): Add two numbers represented by linked lists, where digits are stored in reverse order, and return the sum as a new linked list. ### Linked List, Recursion - [Merge Two Sorted Lists](https://rulcode.com/problem/merge-two-sorted-lists): You are given the heads of two sorted linked lists list1 and list2. Merge the two lists into one sorted list. The list should be made by splicing toge... - [Reverse a Linked List](https://rulcode.com/problem/reverse-linked-list): Given the head of a singly linked list, reverse the list, and return the reversed list. Example: Input: head = [1,2,3,4,5] Output: [5,4,3,2,1] Appro... ### Linked List, Stack, Math & Geometry - [Add Two Numbers II](https://rulcode.com/problem/add-two-numbers-ii): Add two numbers represented by linked lists where the most significant digit comes first. ### Linked List, Two Pointers - [Remove Nth Node From End Of List](https://rulcode.com/problem/remove-nth-node-from-end-of-list): Given the head of a linked list, remove the nth node from the end of the list and return its head. Example: Input: head = [1,2,3,4,5], n = 2 Output: ... ### Linked List, Two Pointers, Stack, Recursion - [Reorder List](https://rulcode.com/problem/reorder-list): You are given the head of a singly linked-list. The list can be represented as: L0 → L1 → … → Ln-1 → Ln. Reorder the list to: L0 → Ln → L1 → Ln-1 → L... ### Math & Geometry - [Reverse Integer](https://rulcode.com/problem/reverse-integer): Reverse the digits of a 32-bit signed integer, handling potential overflow. ### Math & Geometry, Hash Table, Two Pointers - [Happy Number](https://rulcode.com/problem/happy-number): Determine if a number is happy by repeatedly replacing it with the sum of the squares of its digits. ### Math & Geometry, Recursion - [Pow(x, n)](https://rulcode.com/problem/powx-n): Implement pow(x, n), which calculates x raised to the power n (i.e., x^n) in O(log n) time. ### Math & Geometry, String - [Multiply Strings](https://rulcode.com/problem/multiply-strings): Given two non-negative integers num1 and num2 represented as strings, return their product as a string without using BigInteger or direct conversion. ### Math & Number Theory - [Karatsuba Multiplication](https://rulcode.com/problem/karatsuba): Fast multiplication algorithm - [GCD (Euclidean)](https://rulcode.com/problem/gcd-euclidean): Euclid's algorithm for GCD - [Sieve of Eratosthenes](https://rulcode.com/problem/sieve-eratosthenes): Generate all primes up to n - [Modular Exponentiation](https://rulcode.com/problem/modular-exponentiation): Fast power with modulo ### Matrix, Array, Hash Table - [Set Matrix Zeroes](https://rulcode.com/problem/set-matrix-zeroes): Given an m × n integer matrix, if an element is 0, set its entire row and column to 0s. You must do it in place. Example: Input: matrix = [[1,1,1],[1... ### Matrix, Array, Math - [Rotate Image](https://rulcode.com/problem/rotate-image): You are given an n × n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). You have to rotate the image in-place. Example: I... ### Matrix, Array, String, DFS, Backtracking - [Word Search](https://rulcode.com/problem/word-search): Given an m × n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequent... ### Recursion, Linked List - [Reverse Nodes in k-Group](https://rulcode.com/problem/reverse-nodes-in-k-group): Reverse the nodes of a linked list k at a time, leaving any remaining nodes at the end as is. ### SQL - [Delete Duplicate Emails](https://rulcode.com/problem/delete-duplicate-emails): Delete duplicate email entries from a Person table, keeping only the one with the smallest id for each unique email. - [Employees Earning More Than Their Managers](https://rulcode.com/problem/employees-earning-more-than-their-managers): Find employees whose salary is strictly greater than their manager's salary using a self-join operation. - [Rising Temperature](https://rulcode.com/problem/rising-temperature): Find the IDs of dates where the temperature was higher than on the preceding day. - [Department Top Three Salaries](https://rulcode.com/problem/department-top-three-salaries): Find employees with salaries in the top three unique salaries for each department. - [Game Play Analysis I](https://rulcode.com/problem/game-play-analysis-i): Find the first login date for each player. - [Duplicate Emails](https://rulcode.com/problem/duplicate-emails): Report all emails that appear more than once in the Person table. - [Department Highest Salary](https://rulcode.com/problem/department-highest-salary): Find employees who have the highest salary in each of their respective departments. - [Second Highest Paid Employee](https://rulcode.com/problem/second-highest-salary): Find the second highest distinct salary from the Employees table, returning NULL if it doesn't exist. - [Customers Who Never Order](https://rulcode.com/problem/customers-who-never-order): Find all customers who have not placed any orders. - [Combine Two Tables](https://rulcode.com/problem/combine-two-tables): Combine information from two tables, displaying NULLs for unmatched rows. - [Consecutive Numbers](https://rulcode.com/problem/consecutive-numbers): Find all numbers that appear at least three times consecutively in a log table. - [Rank Scores](https://rulcode.com/problem/rank-scores): Find the rank of scores from highest to lowest, where tied scores have the same rank and there are no gaps in the ranking sequence. - [Managers with at Least Five Direct Reports](https://rulcode.com/problem/managers-with-at-least-5-direct-reports): Find the names of managers who supervise a minimum of five employees directly. - [Employee Bonus](https://rulcode.com/problem/employee-bonus): Report the name and bonus amount of each employee who has a bonus less than 1000 or did not get any bonus. - [Game Play Analysis IV](https://rulcode.com/problem/game-play-analysis-iv): Calculate the fraction of players who logged in the day after their first login, rounded to 2 decimal places. - [Nth Highest Salary](https://rulcode.com/problem/nth-highest-salary): Finds the Nth highest distinct salary from the Employee table, returning null if not enough distinct salaries exist. ### Stack, Design Pattern - [Min Stack](https://rulcode.com/problem/min-stack): Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. ### Stack, Design Pattern, Queue - [Implement Queue using Stacks](https://rulcode.com/problem/implement-queue-using-stacks): Implement a first in first out (FIFO) queue using only two stacks. ### Stack, Monotonic Stack - [Monotonic Stack](https://rulcode.com/problem/monotonic-stack): Stack with monotonic properties for efficient queries ### Stack, Sorting, Array - [Car Fleet](https://rulcode.com/problem/car-fleet): Find the number of car fleets that will arrive at the destination. ### String - [Word Ladder](https://rulcode.com/problem/word-ladder): Find the shortest transformation sequence from a beginWord to an endWord, using a dictionary wordList, where adjacent words differ by a single letter. ### String, Array, Hash Table, Sorting - [Group Anagrams](https://rulcode.com/problem/group-anagrams): Given an array of strings strs, group the anagrams together. You may return the answer in any order. Example 1: Input: strs = ["eat","tea","tan","ate... ### String, Dynamic Programming - [Distinct Subsequences](https://rulcode.com/problem/distinct-subsequences): Given two strings s and t, find the number of distinct subsequences of s that equal t. - [Interleaving String](https://rulcode.com/problem/interleaving-string): Determine if a third string s3 is formed by an interleaving of two other strings s1 and s2, maintaining the relative order of characters. ### String, Dynamic Programming, Backtracking - [Palindrome Partitioning](https://rulcode.com/problem/palindrome-partitioning): Given a string, find all possible palindrome partitioning of the string. ### String, Hash Table, Backtracking - [ Letter Combinations of a Phone Number](https://rulcode.com/problem/letter-combinations-of-a-phone-number): Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. ### String, Hash Table, Sliding Window - [Minimum Window Substring](https://rulcode.com/problem/minimum-window-substring): Given two strings s and t, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. I... - [Longest Substring Without Repeating Characters](https://rulcode.com/problem/longest-substring-without-repeating-characters): Given a string s, find the length of the longest substring in which no character appears more than once. Example 1: Input: s = "abcabcbb" Output: 3 E... ### String, Hash Table, Sorting - [Valid Anagram](https://rulcode.com/problem/valid-anagram): Given two strings s and t, return true if t is an anagram of s, and false otherwise. An anagram means the two strings contain the same characters with... ### String, Sliding Window, Hash Table - [Longest Repeating Character Replacement](https://rulcode.com/problem/longest-repeating-character-replacement): You are given a string s and an integer k. You may change at most k characters in s; each change converts one character to any other uppercase English... ### String, Stack - [Valid Parentheses](https://rulcode.com/problem/valid-parentheses): Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: ... ### String, Two Pointers - [Valid Palindrome](https://rulcode.com/problem/valid-palindrome): A phrase is a palindrome if, after converting all uppercase letters into lowercase letters and removing all non-alphanumeric characters, it reads the ... ### String, Two Pointers, 1-D Dynamic Programming - [Longest Palindromic Substring](https://rulcode.com/problem/longest-palindromic-substring): Given a string s, return the longest palindromic substring in s. Example 1: Input: s = "babad" Output: "bab" Note: "aba" is also a valid answer. Exa... - [Palindromic Substrings](https://rulcode.com/problem/palindromic-substrings): Given a string s, return the number of palindromic substrings in it. A substring is palindromic if it reads the same backward as forward. Example 1: ... ### Tree - [Recover BST](https://rulcode.com/problem/recover-bst): Fix BST with two swapped nodes - [DFS Postorder](https://rulcode.com/problem/dfs-postorder): Visit left, right, then root - [BFS Level Order](https://rulcode.com/problem/bfs-level-order): Traverse tree level by level - [DFS Inorder](https://rulcode.com/problem/dfs-inorder): Visit left, root, then right subtree - [DFS Preorder](https://rulcode.com/problem/dfs-preorder): Visit root, left, then right subtree - [Lowest Common Ancestor](https://rulcode.com/problem/lca): Find LCA of two nodes in tree - [BST Insert](https://rulcode.com/problem/bst-insert): Insert node in binary search tree ### Tree, 1-D Dynamic Programming, DFS, BFS - [Binary Tree Maximum Path Sum](https://rulcode.com/problem/binary-tree-maximum-path-sum): A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node may appear at mos... ### Tree, Array, String, Backtracking, Trie, Matrix - [Word Search II](https://rulcode.com/problem/word-search-ii): Given an m × n board of characters and a list of strings words, return all words on the board. Each word must be constructed from letters of sequentia... ### Tree, Binary Tree, BST, BFS, DFS - [Lowest Common Ancestor of BST](https://rulcode.com/problem/lowest-common-ancestor-of-bst): Given a binary search tree (BST) and two nodes p and q, find the lowest common ancestor (LCA) — the deepest node in the tree that has both p and q as ... ### Tree, BST, BFS - [Binary Tree Level Order Traversal](https://rulcode.com/problem/binary-tree-level-order-traversal): Given the root of a binary tree, return the level order traversal of its nodes' values (i.e., from left to right, level by level). ### Tree, BST, BFS, DFS - [Invert/Flip Binary Tree](https://rulcode.com/problem/invert-binary-tree): Given the root of a binary tree, invert the tree and return its root. Example 1: Input: root = [4,2,7,1,3,6,9] Output: [4,7,2,9,6,3,1] Constraints: ... ### Tree, BST, Hash Table, Divide and Conquer - [Construct Binary Tree from Preorder and Inorder Traversal](https://rulcode.com/problem/construct-binary-tree-from-preorder-and-inorder-traversal): Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is the inorder traversal of the sa... ### Tree, Design Pattern - [Serialize Tree](https://rulcode.com/problem/serialize-tree): Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored or transmitted. Design an algor... - [Trie (Prefix Tree)](https://rulcode.com/problem/trie): Efficient string storage and retrieval ### Tree, Design Pattern, Binary Tree, Data Stream, Heap / Priority Queue - [Kth Largest Element in a Stream](https://rulcode.com/problem/kth-largest-element-in-a-stream): Design a class to find the kth largest element in a stream. ### Tree, DFS, BFS, Binary Tree - [Maximum Depth of Binary Tree](https://rulcode.com/problem/maximum-depth-of-binary-tree): Find the maximum depth (height) of a binary tree. ### Tree, DFS, BFS, BST - [Same Tree](https://rulcode.com/problem/same-tree): Given the roots of two binary trees p and q, write a function to check if they are the same tree. Two binary trees are the same if they are structural... ### Tree, DFS, BFS, Union Find, Graph - [Validate Binary Search Tree](https://rulcode.com/problem/validate-binary-search-tree): Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST requires that for every node, all nodes in the left ... ### Tree, DFS, BST, Binary Tree - [Kth Smallest Element in a BST](https://rulcode.com/problem/kth-smallest-element-in-a-bst): Given the root of a binary search tree and an integer k, return the kth smallest value (1-indexed) of all the node values in the tree. Example: Input... ### Tree, DFS, String Matching, BST, Hash Function - [Subtree of Another Tree](https://rulcode.com/problem/subtree-of-another-tree): Given the roots of two binary trees root and subRoot, return true if there is a subtree of root that has the same structure and node values as subRoot... ### Tree, String, DFS, BFS, Design Pattern, BST - [Serialize and Deserialize Binary Tree](https://rulcode.com/problem/serialize-and-deserialize-binary-tree): Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored or transmitted. Design an algor... ### Tree, String, Hash Table - [Implement Trie (Prefix Tree)](https://rulcode.com/problem/implement-trie): Implement the Trie (Prefix Tree) data structure with methods insert(word), search(word) and startsWith(prefix). Example: Input: ["Trie","insert","sea... ### Tree, Trie, Design Pattern, DFS, String - [Add and Search Word](https://rulcode.com/problem/add-and-search-word): Design a data structure that supports adding new words and searching for a string, where the search string may contain the wildcard character '.' that... ### Trees, Binary Tree, BFS, DFS - [Binary Tree Right Side View](https://rulcode.com/problem/binary-tree-right-side-view): Given a binary tree, return the values of the nodes visible from its right side, ordered from top to bottom. ### Trees, DFS, BFS, Binary Tree - [Count Good Nodes in Binary Tree](https://rulcode.com/problem/count-good-nodes-in-binary-tree): Count nodes where their value is greater than or equal to all preceding nodes on the path from the root. ### Trees, DFS, Binary Tree - [Balanced Binary Tree](https://rulcode.com/problem/balanced-binary-tree): Determine if a given binary tree is height-balanced, meaning the depths of the two subtrees of every node never differ by more than one. - [Diameter of Binary Tree](https://rulcode.com/problem/diameter-of-binary-tree): Find the length of the longest path between any two nodes in a binary tree. ### Two Pointers, Array - [Remove Element](https://rulcode.com/problem/remove-element): Remove all occurrences of a specified value from an integer array in-place and return the new length. - [Find Duplicate](https://rulcode.com/problem/find-the-duplicate-number): Given an array of integers, find the duplicate number without modifying the array and using constant extra space. ### Two Pointers, Dynamic Programming, Stack, Monotonic Stack - [Trapping Rain Water](https://rulcode.com/problem/trapping-rain-water): Compute how much water an elevation map can trap after raining. ### Two Pointers, Sorting - [ Merge Sorted Array](https://rulcode.com/problem/merge-sorted-array): Merge two sorted integer arrays, nums1 and nums2, into nums1 in non-decreasing order, modifying nums1 in-place. ### Two Pointers, Sorting, Heap / Priority Queue, Data Stream - [Find Median from Data Stream](https://rulcode.com/problem/find-median-from-data-stream): Design a data structure that supports adding numbers from a data stream and finding the median of all numbers seen so far efficiently. Example: addNu... ### Two Pointers, String - [Reverse String](https://rulcode.com/problem/reverse-string): Reverse a string represented as a character array in-place with O(1) extra memory. - [Merge Strings Alternately](https://rulcode.com/problem/merge-strings-alternately): Merge two strings by adding letters in alternating order, starting with the first string, and appending any remaining characters. ### Two Pointers, String, Greedy - [Valid Palindrome II](https://rulcode.com/problem/valid-palindrome-ii): Given a string s, return true if s can be a palindrome after deleting at most one character. ### Two Poniters, Binary Search - [Two Sum II - Input Array Is Sorted](https://rulcode.com/problem/two-sum-ii-input-array-is-sorted): Find two numbers in a 1-indexed sorted array that sum to a target, returning their 1-indexed positions.