Learnitweb

Author: Editorial Team

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

  • Merge k Sorted Lists

    1. Problem Summary You are given an array of k linked lists, where each list is: Your task is to merge all k linked lists into one single sorted linked list and return its head. Example: 2. Key Insights Insight 1: Naive concatenation then sort is inefficient Concatenating and sorting results in: but loses benefits…

  • Insert into a Binary Search Tree

    1. Problem Summary You are given: Your task is to insert val into the BST while maintaining BST properties and return the updated root. Important points: Example: 2. Key Insights Insight 1: BST insertion follows binary search direction If: Insight 2: Insert when null child encountered When traversal reaches a null position, create new node.…

  • Pairs of Songs With Total Durations Divisible by 60

    1. Problem Summary You are given an integer array time, where each element represents the duration of a song in seconds. Your task is to determine how many pairs (i, j) exist such that: Important details: Example: 2. Key Insights Insight 1: Modulo remainder drives the condition Instead of checking sums, we examine: Insight 2:…

  • Range Sum of BST

    1. Problem Summary You are given the root of a Binary Search Tree (BST) and two integers low and high. Your task is to compute the sum of all node values such that: Important details: Example: 2. Key Insights Insight 1: BST ordering allows pruning Because: We can skip entire subtrees: Insight 2: Better than…

  • LeetCode Problem 1306 Jump Game III

    1. Problem Summary You are given an integer array arr and a starting index start. From index i, you may move to: Your task is to determine whether it is possible to reach any index with value 0. Rules and constraints: Example: 2. Key Insights Insight 1: This is a reachability problem We are exploring…