Learnitweb

Author: Editorial Team

  • 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.…

  • Android Unlock Patterns

    Problem summary Given the 3×3 Android lock screen grid numbered like this: A pattern is a sequence of distinct keys (no repeats) where each move from key a to key b must follow this rule: Given integers m and n (1 ≤ m ≤ n ≤ 9), return the number of valid unlock patterns with…

  • LeetCode 818 — Race Car

    Problem summary You start at position 0 with speed 1. You can issue two instructions: Given a target position (positive integer), return the minimum length of an instruction sequence that reaches exactly that target. ExamplesInput: target = 3Output: 2Explanation: AA (after two A: position 3) Input: target = 6Output: 5One optimal sequence: AAARA — after…

  • LeetCode 4: Median of Two Sorted Arrays

    Problem summary You are given two sorted arrays nums1 and nums2 of sizes m and n.Find the median of the two sorted arrays. The overall run time complexity should be O(log(min(m, n))).The median is the middle value for odd total length, or the average of two middle values for even total length. ExamplesInput: nums1 =…

  • LeetCode 3: Longest Substring Without Repeating Characters

    Problem Summary You are given a string s.Your task is to find the length of the longest substring that contains no repeated characters. A substring means a continuous block of characters. ExamplesInput: “abcabcbb”Output: 3Explanation: The longest substring without repeating characters is “abc”. Input: “bbbbb”Output: 1Explanation: The longest substring without repeating characters is “b”. Input: “pwwkew”Output:…

  • LeetCode 2: Add Two Numbers

    Problem Summary You are given two non-empty singly linked lists that represent two non-negative integers.Each linked list stores the digits in reverse order.Each node contains one digit from 0–9. Your task is to add the two numbers and return the sum as a linked list in the same reverse order format. Examplel1 = 2 →…