# Leetcode > Documentation for LeetCode solutions ## Docs - [Introduction](https://lc.prd.lk/): Structured dependency spine based roadmap for solving DSA Problems on leetcode. - [Progress](https://lc.prd.lk/progress): Live SRS campaign dashboard — phases, ladder, review queue, gates, and recent attempts, fetched from the SRS Worker. ## Phase 1: Linear Structures ### Hash Table - [1. Two Sum](https://lc.prd.lk/hash-table/two-sum): You are given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target - [49. Group Anagrams](https://lc.prd.lk/hash-table/group-anagrams): Given an array of strings strs, group the anagrams together. You can return the answer in any order - [217. Contains Duplicate](https://lc.prd.lk/hash-table/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 - [242. Valid Anagram](https://lc.prd.lk/hash-table/valid-anagram): Given two strings s and t, return true if t is an anagram of s, and false otherwise - [347. Top K Frequent Elements](https://lc.prd.lk/hash-table/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 - [387. First Unique Character in a String](https://lc.prd.lk/hash-table/first-unique-character-in-a-string): Given a string s, find the first non-repeating character in it and return its index. If it does not exist, return -1 - [451. Sort Characters By Frequency](https://lc.prd.lk/hash-table/sort-characters-by-frequency): Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string - [1832. Check if the Sentence Is Pangram](https://lc.prd.lk/hash-table/check-if-the-sentence-is-pangram): A pangram is a sentence where every letter of the English alphabet appears at least once ### Prefix Sum - [238. Product of Array Except Self](https://lc.prd.lk/prefix-sum/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] - [303. Range Sum Query - Immutable](https://lc.prd.lk/prefix-sum/range-sum-query-immutable): Given an integer array nums, handle multiple queries of the following type - [560. Subarray Sum Equals K](https://lc.prd.lk/prefix-sum/subarray-sum-equals-k): Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals to k ### Two Pointers - [11. Container With Most Water](https://lc.prd.lk/two-pointers/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 i^th line are (i, 0) and (i, height[i]) - [15. 3Sum](https://lc.prd.lk/two-pointers/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] == 0 - [125. Valid Palindrome](https://lc.prd.lk/two-pointers/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 same forward and backward. Alphanumeric characters include letters and numbers - [167. Two Sum II - Input Array Is Sorted](https://lc.prd.lk/two-pointers/two-sum-ii-input-array-is-sorted): Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be numbers[index1] and numbers[index2] where 1 <= index1 < index2 <= numbers.length - [344. Reverse String](https://lc.prd.lk/two-pointers/reverse-string): Write a function that reverses a string. The input string is given as an array of characters s - [392. Is Subsequence](https://lc.prd.lk/two-pointers/is-subsequence): Given two strings s and t, return true if s is a subsequence of t, or false otherwise - [977. Squares of a Sorted Array](https://lc.prd.lk/two-pointers/squares-of-a-sorted-array): Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order ### Sliding Window - [3. Longest Substring Without Repeating Characters](https://lc.prd.lk/sliding-window/longest-substring-without-repeating-characters): Given a string s, find the length of the longest substring without duplicate characters - [121. Best Time to Buy and Sell Stock](https://lc.prd.lk/sliding-window/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 i^th day - [424. Longest Repeating Character Replacement](https://lc.prd.lk/sliding-window/longest-repeating-character-replacement): You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at most k times - [567. Permutation in String](https://lc.prd.lk/sliding-window/permutation-in-string): Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise ### Binary Search - [33. Search in Rotated Sorted Array](https://lc.prd.lk/binary-search/search-in-rotated-sorted-array): There is an integer array nums sorted in ascending order (with distinct values) - [35. Search Insert Position](https://lc.prd.lk/binary-search/search-insert-position): Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order - [74. Search a 2D Matrix](https://lc.prd.lk/binary-search/search-a-2d-matrix): You are given an m x n integer matrix matrix with the following two properties: - [153. Find Minimum in Rotated Sorted Array](https://lc.prd.lk/binary-search/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: - [704. Binary Search](https://lc.prd.lk/binary-search/binary-search): Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1 - [875. Koko Eating Bananas](https://lc.prd.lk/binary-search/koko-eating-bananas): Koko loves to eat bananas. There are n piles of bananas, the i^th pile has piles[i] bananas. The guards have gone and will come back in h hours ### Stack - [20. Valid Parentheses](https://lc.prd.lk/stack/valid-parentheses): Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid - [150. Evaluate Reverse Polish Notation](https://lc.prd.lk/stack/evaluate-reverse-polish-notation): You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation - [155. Min Stack](https://lc.prd.lk/stack/min-stack): Design a stack that supports push, pop, top, and retrieving the minimum element in constant time ### Monotonic Stack - [739. Daily Temperatures](https://lc.prd.lk/monotonic-stack/daily-temperatures): Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the i^th day to get a warmer temperature. If there is no future day for which this is possible, keep answer[i] == 0 instead - [853. Car Fleet](https://lc.prd.lk/monotonic-stack/car-fleet): There are n cars at given miles away from the starting mile 0, traveling to reach the mile target ## Phase 2: Nodal & Grid ### Linked List - [21. Merge Two Sorted Lists](https://lc.prd.lk/linked-list/merge-two-sorted-lists): You are given the heads of two sorted linked lists list1 and list2 - [141. Linked List Cycle](https://lc.prd.lk/linked-list/linked-list-cycle): Given head, the head of a linked list, determine if the linked list has a cycle in it - [206. Reverse Linked List](https://lc.prd.lk/linked-list/reverse-linked-list): Given the head of a singly linked list, reverse the list, and return the reversed list ### Hybrid Structures - [2. Add Two Numbers](https://lc.prd.lk/hybrid-structures/add-two-numbers): You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list - [146. LRU Cache](https://lc.prd.lk/hybrid-structures/lru-cache): Design a data structure that follows the constraints of a Least Recently Used (LRU) cache ### Matrix Index Math - [48. Rotate Image](https://lc.prd.lk/matrix-index-math/rotate-image): You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise) - [54. Spiral Matrix](https://lc.prd.lk/matrix-index-math/spiral-matrix): Given an m x n matrix, return all elements of the matrix in spiral order - [73. Set Matrix Zeroes](https://lc.prd.lk/matrix-index-math/set-matrix-zeroes): Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0's ## Phase 3: Hierarchical ### Tree DFS - [104. Maximum Depth of Binary Tree](https://lc.prd.lk/tree-dfs/maximum-depth-of-binary-tree): Given the root of a binary tree, return its maximum depth - [226. Invert Binary Tree](https://lc.prd.lk/tree-dfs/invert-binary-tree): Given the root of a binary tree, invert the tree, and return its root - [236. Lowest Common Ancestor of a Binary Tree](https://lc.prd.lk/tree-dfs/lowest-common-ancestor-of-a-binary-tree): Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree ### Tree BFS - [102. Binary Tree Level Order Traversal](https://lc.prd.lk/tree-bfs/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) - [199. Binary Tree Right Side View](https://lc.prd.lk/tree-bfs/binary-tree-right-side-view): Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom - [1448. Count Good Nodes in Binary Tree](https://lc.prd.lk/tree-bfs/count-good-nodes-in-binary-tree): Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X ### Binary Search Tree - [98. Validate Binary Search Tree](https://lc.prd.lk/binary-search-tree/validate-binary-search-tree): Given the root of a binary tree, determine if it is a valid binary search tree (BST) - [230. Kth Smallest Element in a BST](https://lc.prd.lk/binary-search-tree/kth-smallest-element-in-a-bst): Given the root of a binary search tree, and an integer k, return the k^th smallest value (1-indexed) of all the values of the nodes in the tree - [235. Lowest Common Ancestor of a Binary Search Tree](https://lc.prd.lk/binary-search-tree/lowest-common-ancestor-of-a-binary-search-tree): Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST ### Heap / Priority Queue - [23. Merge k Sorted Lists](https://lc.prd.lk/heap-priority-queue/merge-k-sorted-lists): You are given an array of k linked-lists lists, each linked-list is sorted in ascending order - [215. Kth Largest Element in an Array](https://lc.prd.lk/heap-priority-queue/kth-largest-element-in-an-array): Given an integer array nums and an integer k, return the k^th largest element in the array - [973. K Closest Points to Origin](https://lc.prd.lk/heap-priority-queue/k-closest-points-to-origin): Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0) ### Trie - [208. Implement Trie (Prefix Tree)](https://lc.prd.lk/trie/implement-trie-prefix-tree): A trie (pronounced as "try") or prefix tree is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker - [211. Design Add and Search Words Data Structure](https://lc.prd.lk/trie/design-add-and-search-words-data-structure): Design a data structure that supports adding new words and finding if a string matches any previously added string ## Phase 4: Relational ### Graph DFS - [133. Clone Graph](https://lc.prd.lk/graph-dfs/clone-graph): Given a reference of a node in a connected undirected graph - [200. Number of Islands](https://lc.prd.lk/graph-dfs/number-of-islands): Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands - [417. Pacific Atlantic Water Flow](https://lc.prd.lk/graph-dfs/pacific-atlantic-water-flow): There is an m x n rectangular island that borders both the Pacific Ocean and Atlantic Ocean. The Pacific Ocean touches the island's left and top edges, and the Atlantic Ocean touches the island's right and bottom edges ### Graph BFS - [127. Word Ladder](https://lc.prd.lk/graph-bfs/word-ladder): A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: - [994. Rotting Oranges](https://lc.prd.lk/graph-bfs/rotting-oranges): You are given an m x n grid where each cell can have one of three values: ### Topological Sort - [207. Course Schedule](https://lc.prd.lk/topological-sort/course-schedule): There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai - [210. Course Schedule II](https://lc.prd.lk/topological-sort/course-schedule-ii): There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai ### Union-Find - [323. Number of Connected Components in an Undirected Graph](https://lc.prd.lk/union-find/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 in the graph - [684. Redundant Connection](https://lc.prd.lk/union-find/redundant-connection): In this problem, a tree is an undirected graph that is connected and has no cycles ## Phase 5: Decision Space ### Backtracking - [39. Combination Sum](https://lc.prd.lk/backtracking/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 numbers sum to target. You may return the combinations in any order - [46. Permutations](https://lc.prd.lk/backtracking/permutations): Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order - [78. Subsets](https://lc.prd.lk/backtracking/subsets): Given an integer array nums of unique elements, return all possible subsets (the power set) ## Agent resources - [llms-full.txt](https://lc.prd.lk/llms-full.txt): The full Markdown of every page in one file. - [Page Markdown](https://lc.prd.lk/index.md): Append `.md` to any page URL to fetch that page as raw Markdown. - [JSON API](https://lc.prd.lk/api/docs/pages.json): Page index of the JSON docs API; each entry links the page's JSON and Markdown forms. Described by the OpenAPI document at https://lc.prd.lk/openapi.json. - [API catalog](https://lc.prd.lk/.well-known/api-catalog): RFC 9727 linkset of the APIs documented here. - [AI catalog](https://lc.prd.lk/.well-known/ai-catalog.json): ARD manifest of the agent-facing resources on this site (MCP server, skills, APIs). - [agent-readability.json](https://lc.prd.lk/agent-readability.json): Manifest of every agent-facing artifact on this site. - [Sitemap](https://lc.prd.lk/sitemap.xml): Every indexable page URL with its last-modified date.