Author: Editorial Team
-
LeetCode 899 — Orderly Queue
Problem Summary You are given a string s and an integer k. You can perform the following operation any number of times: Your task is to return the lexicographically smallest string you can obtain after applying any number of operations. ExamplesInput: s = “cba”, k = 1Output: “acb” Input: s = “baaca”, k = 3Output:…
-
LeetCode 98 — Validate Binary Search Tree
Problem Summary You are given the root of a binary tree.Your task is to determine whether the tree is a valid Binary Search Tree (BST). A valid BST must satisfy: ExampleInput: Output: true Input: Output: falseReason: The right subtree contains 3, which is not greater than 5. Approach 1: Recursion Using Min/Max Boundaries (Most Common…
-
LeetCode 843 — Guess the Word
Problem Summary This is an interactive problem.You are given a secret word chosen from a list of unique words.Each word has exactly 6 lowercase letters. You do not know which word is the secret word, but you can call: This function returns the number of positions where the guessed word matches the secret word exactly.…
-
LeetCode 653 — Two Sum IV: Input is a BST
Problem Summary You are given the root of a Binary Search Tree (BST) and an integer k.Your task is to determine whether there exist two distinct nodes in the tree whose values sum to k. Return true if such a pair exists; otherwise return false. Example BST: Example queries:For k = 9, output is true…
-
LeetCode 16 — 3Sum Closest
Problem Summary You are given an integer array nums and an integer target.Your task is to find three distinct integers in the array such that their sum is closest to target.Return that sum. There is guaranteed to be exactly one solution. ExampleInput: nums = [-1, 2, 1, -4], target = 1Output: 2Explanation: The closest sum…
-
LeetCode 653 — Two Sum IV: Input is a BST
Problem Summary You are given the root of a Binary Search Tree (BST) and an integer k.Your task is to determine whether the tree contains two distinct nodes whose values sum to k. Return true if such a pair exists, otherwise return false. Example BST: Example queries:For k = 9, output is true (2 +…
-
LeetCode 16 — 3Sum Closest
Problem Summary You are given an integer array nums and an integer target.Your task is to find three integers in nums such that the sum is closest to target.Return that sum. You may assume there is exactly one solution. ExampleInput: nums = [-1, 2, 1, -4], target = 1Output: 2Explanation: The sum that is closest…
-
LeetCode 981 — Time Based Key-Value Store
Problem Statement Design a data structure that stores multiple values for the same key, each associated with a timestamp, and returns the value for a key at the largest timestamp less than or equal to the given timestamp. You must implement two operations: Example Constraints Approach (Simple English) The main requirement is:Given a key and…
-
LeetCode 22 — Generate Parentheses
Problem statement Given n pairs of parentheses, generate all combinations of well-formed (valid) parentheses.Return the list of all valid strings. ExamplesInput: n = 3Output: [“((()))”,”(()())”,”(())()”,”()(())”,”()()()”] Input: n = 1Output: [“()”] Constraints1 ≤ n ≤ 8 (typical). Number of valid combinations grows combinatorially (Catalan numbers). Approach in simple English The task is to generate every string…
-
LeetCode 112 — Path Sum
Problem statement Given the root of a binary tree and an integer targetSum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.A leaf is a node with no children. ExampleInput: targetSum = 22Output: trueExplanation: 5 → 4 → 11 → 2 sums to 22.…
