600+ Bài tập lập trình tổng hợp Beta
Chào mừng bạn đến với trang tổng hợp 600+ bài tập lập trình! Danh sách này được thiết kế để giúp bạn rèn luyện tư duy thuật toán từ mức độ cơ bản cho người mới bắt đầu đến nâng cao (tham khảo các nền tảng như LeetCode, HackerRank).
Các bài tập có thể được giải bằng bất kỳ ngôn ngữ lập trình nào (Python, C++, Java, JavaScript, Kotlin, Swift,…).
Basic Input/Output & Math
1: Hello World 🟢 Easy
- Problem: Print
Hello, World!to the screen. - Example:
Output: Hello, World!
2: Print an Integer 🟢 Easy
- Problem: Read an integer
nfrom keyboard and print it to the screen. - Example:
- Input:
5 - Output:
5 - Explanation: The input 5 is printed directly.
- Input:
3: Sum of Two Integers 🟢 Easy
- Problem: Read two integers
aandb. Print their sum. - Example:
- Input:
3 5 - Output:
8 - Explanation: 3 + 5 = 8
- Input:
4: Difference, Product, Quotient 🟢 Easy
- Problem: Read two integers
a, b(b != 0). Print their difference, product, and integer quotient, each on a new line. - Example:
- Input:
10 3 - Output:
7, 30, 3 - Explanation: 10 - 3 = 7; 10 * 3 = 30; 10 // 3 = 3
- Input:
5: Perimeter and Area of Rectangle 🟢 Easy
- Problem: Read the length
aand widthbof a rectangle. Calculate its perimeter and area. - Example:
- Input:
4 5 - Output:
18, 20 - Explanation: Perimeter = 2*(4+5) = 18; Area = 4*5 = 20
- Input:
6: Perimeter and Area of Circle 🟢 Easy
- Problem: Read the radius
r. Calculate perimeter (2 * pi * r) and area (pi * r^2) (usepi = 3.14, round to 2 decimal places). - Example:
- Input:
5 - Output:
31.40, 78.50 - Explanation: Perimeter = 2 * 3.14 * 5 = 31.40; Area = 3.14 * 5^2 = 78.50
- Input:
7: Power 🟢 Easy
- Problem: Read two integers
aandn. Calculatea^n. - Example:
- Input:
2 3 - Output:
8 - Explanation: 2 raised to the power of 3 is 2 * 2 * 2 = 8
- Input:
8: Average Score 🟢 Easy
- Problem: Read 3 scores for Math, Physics, Chemistry. Print the average score (round to 1 decimal place).
- Example:
- Input:
8 7.5 9 - Output:
8.2 - Explanation: (8 + 7.5 + 9) / 3 = 8.166… rounded to 8.2
- Input:
9: Reverse a 2-Digit Number 🟢 Easy
- Problem: Read a positive 2-digit integer. Print its reversed number.
- Example:
- Input:
47 - Output:
74 - Explanation: The tens and units digits are swapped.
- Input:
10: Time Conversion 🟢 Easy
- Problem: Read the number of seconds
s. Print inHour:Minute:Secondformat. - Example:
- Input:
3665 - Output:
1:1:5 - Explanation: 3665 seconds = 1 hour, 1 minute, 5 seconds.
- Input:
Control Flow (If/Else)
11: Check Even or Odd 🟢 Easy
- Problem: Read an integer
n. PrintEvenifnis even,Oddifnis odd. - Example:
- Input:
4 - Output:
Even - Explanation: 4 is divisible by 2, so it’s Even.
- Input:
12: Check Positive or Negative 🟢 Easy
- Problem: Read an integer
n. PrintPositiveif it’s positive,Negativeif negative,Zeroif it’s 0. - Example:
- Input:
-5 - Output:
Negative - Explanation: 3 is not divisible by 2, so it’s Odd.
- Input:
13: Find Maximum of Two Numbers 🟢 Easy
- Problem: Read
aandb. Print the larger number. - Example:
- Input:
7 12 - Output:
12 - Explanation: 1999 is not divisible by 4, so it’s a common year.
- Input:
14: Find Maximum of Three Numbers 🟢 Easy
- Problem: Read
a, b, c. Print the largest number. - Example:
- Input:
4 9 2 - Output:
9 - Explanation: 2000 is divisible by 400, so it’s a leap year.
- Input:
15: Check Leap Year 🟢 Easy
- Problem: Read a year
N. PrintYesif it’s a leap year,Nootherwise. (A leap year is divisible by 400 or divisible by 4 but not by 100). - Example:
- Input:
2024 - Output:
Yes - Explanation: 8 is the largest among 3, 8, 5.
- Input:
16: Classify Student Grade 🟢 Easy
- Problem: Read a final score (0-10).
< 5: Weak,5-6.5: Average,6.5-8: Good,> 8: Excellent. - Example:
- Input:
7.5 - Output:
Good - Explanation: Roots: x1 = 2, x2 = 1. Output order: 2 1
- Input:
17: Solve Linear Equation 🟢 Easy
- Problem: Solve the equation
ax + b = 0. Reada, b. Print the root rounded to 2 decimal places, orNo solution,Infinite solutions. - Example:
- Input:
2 -4 - Output:
2.00 - Explanation: 5 is positive, so absolute value is 5.
- Input:
18: Solve Quadratic Equation 🟢 Easy
- Problem: Solve
ax^2 + bx + c = 0. Print the roots rounded to 2 decimal places. - Example:
- Input:
1 -5 6 - Output:
3.00 2.00 - Explanation: Only triangle of sides 3, 4, 5 is valid because 3+4>5, 3+5>4, 4+5>3.
- Input:
19: Check Valid Triangle 🟢 Easy
- Problem: Read 3 sides
a, b, c. PrintYesif they form a valid triangle,Nootherwise. - Example:
- Input:
3 4 5 - Output:
Yes - Explanation: Sum of integers from 1 to 5: 1+2+3+4+5 = 15
- Input:
20: Classify Triangle 🟢 Easy
- Problem: Read 3 valid sides of a triangle. Classify it as:
Equilateral,Right,Isosceles,Scalene. - Example:
- Input:
3 4 5 - Output:
Right - Explanation: Sum of integers from 1 to 10: 55
- Input:
Loops (For/While)
21: Print Sequence 1 to N 🟢 Easy
- Problem: Read a positive integer
N. Print numbers from 1 toN, separated by space. - Example:
- Input:
5 - Output:
1 2 3 4 5 - Explanation: Factorial of 5: 5! = 120
- Input:
22: Print Even Sequence 🟢 Easy
- Problem: Read
n. Print even numbers from 1 ton. - Example:
- Input:
7 - Output:
2 4 6 - Explanation: Fibonacci sequence: 0, 1, 1, 2, 3, 5…
- Input:
23: Sum 1 to N 🟢 Easy
- Problem: Read
N. Calculate and print the sumS = 1 + 2 + ... + N. - Example:
- Input:
4 - Output:
10 - Explanation: GCD of 12 and 18 is 6.
- Input:
24: Calculate Factorial 🟢 Easy
- Problem: Read
N. CalculateN! = 1 * 2 * ... * N. - Example:
- Input:
5 - Output:
120 - Explanation: LCM of 4 and 6 is 12.
- Input:
25: Multiplication Table 🟢 Easy
- Problem: Read
N(1-9). Print the multiplication table forN. - Example:
- Input:
2 - Output:
2 x 1 = 2 ... 2 x 10 = 20 - Explanation: 7 has only 1 and 7 as divisors, so it’s prime.
- Input:
26: Count Digits of an Integer 🟢 Easy
- Problem: Read a positive integer
N. Print the number of digits inN. - Example:
- Input:
12345 - Output:
5 - Explanation: 6 is divisible by 2 and 3, so it’s not prime.
- Input:
27: Sum of Digits 🟢 Easy
- Problem: Read a positive integer
N. Calculate the sum of its digits. - Example:
- Input:
246 - Output:
12 - Explanation: Sum of prime numbers
<= 10: 2+3+5+7 = 17
- Input:
28: Check Prime Number 🟢 Easy
- Problem: Read
N. PrintYesifNis a prime number, otherwise printNo. - Example:
- Input:
7 - Output:
Yes - Explanation: The first 5 primes: 2, 3, 5, 7, 11
- Input:
29: Print Prime Numbers from 1 to N 🟢 Easy
- Problem: Read
N. Print all prime numbers from 1 toN. - Example:
- Input:
10 - Output:
2 3 5 7 - Explanation: 153 = 1^3 + 5^3 + 3^3, so it’s an Armstrong number.
- Input:
30: Find the Greatest Common Divisor (GCD) 🟢 Easy
- Problem: Read two positive integers
aandb. Find their greatest common divisor. - Example:
- Input:
12 18 - Output:
6 - Explanation: 28 = 1 + 2 + 4 + 7 + 14, so it’s a perfect number.
- Input:
1D Arrays (List)
31: Input and Print Array 🟢 Easy
- Problem: Read an integer
n(array size) andnelements. Print the array. - Example:
- Input:
3, 1 2 3 - Output:
1 2 3 - Explanation: Palindromic number reads the same forwards and backwards.
- Input:
32: Sum of Array Elements 🟢 Easy
- Problem: Read an array of
nelements. Calculate the sum of all elements. - Example:
- Input:
4, 1 2 3 4 - Output:
10 - Explanation: Sum of squares: 1^2 + 2^2 + 3^2 = 14
- Input:
33: Find Maximum Element 🟢 Easy
- Problem: Print the largest value in the array.
- Example:
- Input:
5, 4 8 2 9 1 - Output:
9 - Explanation: Count integer divisions by 10 until 0. 12345 has 5 digits.
- Input:
34: Find Minimum Element 🟢 Easy
- Problem: Print the smallest value in the array.
- Example:
- Input:
5, 4 8 2 9 1 - Output:
1 - Explanation: 1 + 2 + 3 + 4 + 5 = 15
- Input:
35: Count Occurrences of x 🟢 Easy
- Problem: Read an array and a number
x. Count how many timesxappears in the array. - Example:
- Input:
5, 1 2 1 4 1, x = 1 - Output:
3 - Explanation: 123 forward is 321 backward.
- Input:
36: Reverse Array 🟢 Easy
- Problem: Reverse the elements of the array and print it.
- Example:
- Input:
3, 1 2 3 - Output:
3 2 1 - Explanation: 123 reversed is 321, not equal.
- Input:
37: Check Increasing Array 🟢 Easy
- Problem: Check if the elements in the array are sorted in strictly increasing order. Print
YesorNo. - Example:
- Input:
4, 1 3 5 8 - Output:
Yes - Explanation: Binary of 10 is 1010.
- Input:
38: List Prime Numbers in Array 🟢 Easy
- Problem: Print all elements in the array that are prime numbers.
- Example:
- Input:
5, 4 7 12 13 9 - Output:
7 13 - Explanation: 1010 in binary is 1 * 8 + 0 * 4 + 1 * 2 + 0 * 1 = 10.
- Input:
39: Insert Element x at Position k 🟢 Easy
- Problem: Read an array, a number
x, and a positionk. Insertxat positionk(0-indexed). - Example:
- Input:
4, 1 2 4 5, x = 3, k = 2 - Output:
1 2 3 4 5 - Explanation: 12 in hex is C.
- Input:
40: Delete Element at Position k 🟢 Easy
- Problem: Delete the element at position
kand print the array after deletion. - Example:
- Input:
4, 1 2 9 3, k = 2 - Output:
1 2 9 - Explanation: 255 in hex is FF.
- Input:
Strings
41: String Length 🟢 Easy
- Problem: Read a string
S. Print its length. - Example:
- Input:
Hello - Output:
5 - Explanation: Reverse of ‘hello’ is ‘olleh’.
- Input:
42: Reverse String 🟢 Easy
- Problem: Read a string
S. Print the reversed string. - Example:
- Input:
abcd - Output:
dcba - Explanation: ‘radar’ is a palindrome.
- Input:
43: Count Vowels and Consonants 🟢 Easy
- Problem: Read an English string
S. Count the number of vowels (a, e, i, o, u) and consonants. - Example:
- Input:
hello - Output:
2 3 - Explanation: Length of ‘hello’ is 5.
- Input:
44: Uppercase and Lowercase Conversion 🟢 Easy
- Problem: Convert all characters in string
Sto UPPERCASE and lowercase. - Example:
- Input:
aBcD - Output:
ABCD, abcd - Explanation: Lowercase a is A, uppercase B is b, etc.
- Input:
45: Check Palindrome String 🟢 Easy
- Problem: Check if the string reads the same forwards and backwards. Print
YesorNo. - Example:
- Input:
madam - Output:
Yes - Explanation: 3 vowels (e, o, o).
- Input:
46: Remove Extra Spaces 🟢 Easy
- Problem: Remove all extra spaces at the beginning, end, and between words. Print the formatted string.
- Example:
- Input:
" Hello World " - Output:
"Hello World" - Explanation: The first word.
- Input:
47: Find and Replace 🟢 Easy
- Problem: Read string
S, words1and words2. Replace all occurrences ofs1inSwiths2. - Example:
- Input:
I like apple, apple, banana - Output:
I like banana - Explanation: ‘Lập trình’ matches exactly.
- Input:
48: Count Words in String 🟢 Easy
- Problem: Count the number of words (separated by spaces) in the string.
- Example:
- Input:
Lap trinh that thu vi - Output:
5 - Explanation: Sum over all elements: 1+2+3+4+5=15
- Input:
49: Character Frequency 🟢 Easy
- Problem: Read string
Sand characterc. Count how many timescappears inS. - Example:
- Input:
banana, a - Output:
3 - Explanation: Max is 5, Min is 1.
- Input:
50: Print Each Word on a New Line 🟢 Easy
- Problem: Read a sentence. Print each word on a new line.
- Example:
- Input:
Xin chao ban - Output:
Xin, chao, ban - Explanation: The array is reversed in-place or printed backwards.
- Input:
2D Arrays (Matrix)
51: Input and Print Matrix 🟢 Easy
- Problem: Read number of rows
mand columnsn. Then read the matrix elements. Print the matrix. - Example:
- Input:
2 3, 1 2 3, 4 5 6 - Output:
1 2 3, 4 5 6 - Explanation: Even numbers: 2, 4. Sum = 6.
- Input:
52: Sum of Matrix Elements 🟢 Easy
- Problem: Calculate the sum of all elements in an
mxnmatrix. - Example:
- Input:
2 2, 1 2, 3 4 - Output:
10 - Explanation: All negative elements are removed.
- Input:
53: Sum of Each Row 🟢 Easy
- Problem: Print the sum of elements for each row of the matrix.
- Example:
- Input:
2 3, 1 2 3, 4 5 6 - Output:
6, 15 - Explanation: Value 3 is present at index 2 (0-indexed).
- Input:
54: Sum of Each Column 🟢 Easy
- Problem: Print the sum of elements for each column of the matrix.
- Example:
- Input:
2 3, 1 2 3, 4 5 6 - Output:
5 7 9 - Explanation: Count frequency of 2: appears 3 times.
- Input:
55: Transpose Matrix 🟢 Easy
- Problem: Print the transpose of the original
mxnmatrix. - Example:
- Input:
2 3, 1 2 3, 4 5 6 - Output:
1 4, 2 5, 3 6 - Explanation: Duplicates removed, keeping unique elements.
- Input:
56: Sum of Main Diagonal 🟢 Easy
- Problem: Read an
nxnsquare matrix. Calculate the sum of elements on the main diagonal (i = j). - Example:
- Input:
3, 1 2 3, 4 5 6, 7 8 9 - Output:
15 - Explanation: 3+4=7 is the required target.
- Input:
57: Add Two Matrices 🟢 Easy
- Problem: Read 2 matrices of the same
mxndimensions. Calculate and print their sum. - Example:
- Input:
2 2, 1 2, 3 4, -, 2 0, 1 3 - Output:
3 2, 4 7 - Explanation: Sum of 1+2+3+4=10
- Input:
58: Find Max, Min in Matrix 🟢 Easy
- Problem: Find the largest and smallest values in the matrix.
- Example:
- Input:
2 2, 4 9, 1 7 - Output:
9 1 - Explanation: Check elements equality backward.
- Input:
59: Check Identity Matrix 🟢 Easy
- Problem: Check if an
nxnsquare matrix is an identity matrix (main diagonal = 1, others = 0). - Example:
- Input:
3, 1 0 0, 0 1 0, 0 0 1 - Output:
Yes - Explanation: Sorted in ascending order.
- Input:
60: Search in Matrix 🟢 Easy
- Problem: Find element
xin anmxnmatrix. PrintYesif found,Nootherwise. - Example:
- Input:
2 2, 1 5, 8 3, 5 - Output:
Yes - Explanation: Merge and sort [1,3,5] and [2,4] -> [1,2,3,4,5]
- Input:
Two Pointers
61: Reverse Array using Two Pointers 🟢 Easy
- Problem: Use two pointers (left, right) to reverse an array.
- Example:
- Input:
1 2 3 4 - Output:
4 3 2 1 - Explanation: Intersection contains common elements 2 and 3.
- Input:
62: Check Palindrome Array 🟢 Easy
- Problem: Check if an array is a palindrome (reads the same forwards and backwards) using two pointers.
- Example:
- Input:
1 2 2 1 - Output:
Yes - Explanation: Union of two arrays, no duplicates.
- Input:
63: Move Zeroes 🟢 Easy
- Problem: (Leetcode) Given an integer array. Move all 0’s to the end of the array while maintaining the relative order of the non-zero elements.
- Example:
- Input:
0 1 0 3 12 - Output:
1 3 12 0 0 - Explanation: Elements in A not in B.
- Input:
64: Sort Even and Odd Numbers 🟢 Easy
- Problem: Move all even numbers to the beginning of the array, and all odd numbers to the end (does not need to maintain original order).
- Example:
- Input:
3 1 2 4 - Output:
2 4 3 1 - Explanation: Subarray with largest sum is [1, 2, -1, 3] = 5.
- Input:
65: Merge Two Sorted Arrays 🟢 Easy
- Problem: Merge 2 ascending sorted arrays
A, Binto 1 ascending sorted arrayCby iterating with two pointers. - Example:
- Input:
A = 1 3 5, B = 2 4 - Output:
1 2 3 4 5 - Explanation: Max difference is 5 - 1 = 4.
- Input:
66: Subarray with Sum S 🟢 Easy
- Problem: Given an array of positive numbers and a number S. Using the sliding window technique or two pointers, check if there is a contiguous subarray whose sum equals S.
- Example:
- Input:
A = 1 2 3 4 5, S = 9 - Output:
Yes - Explanation: because 2 + 3 + 4 = 9, or 4 + 5 = 9
- Input:
67: Two Sum II 🟢 Easy
- Problem: (Two Sum II - Leetcode) Given a sorted array. Find 2 numbers that add up to a given Target. Print those 2 values.
- Example:
- Input:
A = 2 7 11 15, Target = 9 - Output:
2 7 - Explanation: Matrix sizes don’t match or calculation step by step.
- Input:
68: Backspace String Compare 🟢 Easy
- Problem: The character ’#’ represents a backspace key. Compare if two typed strings are equal.
- Example:
- Input:
a#c and b - Output:
No - Explanation: because ‘a#c’ -> ‘c’, ‘b’ -> ‘b’
- Input:
69: Is Subsequence 🟢 Easy
- Problem: Given 2 strings s and t. Check if s is a subsequence of t (maintains relative order, only deletes characters).
- Example:
- Input:
s = "abc", t = "ahbgdc" - Output:
Yes - Explanation: Count unique chars. ‘apple’ -> a,p,l,e (4)
- Input:
70: Find Missing Number in Array 🟢 Easy
- Problem: An array of size
n-1contains numbers from1ton. Find the missing number. (O(N) time, O(1) space solution). - Example:
- Input:
n = 4, A = 1 4 3 - Output:
2 - Explanation: Check character frequency matching.
- Input:
Strings - Advanced
71: Reverse Vowels of a String 🔴 Hard
- Problem: (Leetcode) Given a string S, reverse only all the vowels in the string.
- Example:
- Input:
hello - Output:
holle - Explanation: ‘a’ appears the most (3 times).
- Input:
72: Valid Anagram 🔴 Hard
- Problem: (Leetcode) Given 2 strings s and t, check if s and t are anagrams of each other.
- Example:
- Input:
s = "anagram", t = "nagaram" - Output:
Yes - Explanation: Count number of words separated by space.
- Input:
73: Longest Common Prefix 🔴 Hard
- Problem: (Leetcode) Find the longest common prefix string amongst an array of strings.
- Example:
- Input:
flower flow flight - Output:
fl - Explanation: First non-repeating is ‘e’ at index 1.
- Input:
74: First Unique Character in a String 🔴 Hard
- Problem: Find the first character in S that appears only once. Print its 0-indexed position. If it doesn’t exist, print -1.
- Example:
- Input:
leetcode - Output:
0 - Explanation: character ‘l’
- Input:
75: Isomorphic Strings 🔴 Hard
- Problem: Check if strings s and t are isomorphic (characters in s can be mapped to get t).
- Example:
- Input:
s = "egg", t = "add" - Output:
Yes - Explanation: Replace characters.
- Input:
76: Roman to Integer 🔴 Hard
- Problem: Read a Roman numeral string (I=1, V=5, X=10, L=50, C=100, D=500, M=1000). Convert it to an integer. (Ignore IV, IX… cases for simplicity).
- Example:
- Input:
XVII - Output:
17 - Explanation: Length of ‘World’ is 5.
- Input:
77: Length of Last Word 🔴 Hard
- Problem: Return the length of the last word in the string S.
- Example:
- Input:
Hello World - Output:
5 - Explanation: Reverse string word by word.
- Input:
78: Add Binary Strings 🔴 Hard
- Problem: Prompt for 2 binary strings, sum them, and return the result as a binary string.
- Example:
- Input:
"11" "1" - Output:
"100" - Explanation: Extract prefix.
- Input:
79: Title Case 🔴 Hard
- Problem: Read a string. Print the string with the first letter of each word capitalized (Title Case).
- Example:
- Input:
lap trinh c++ - Output:
Lap Trinh C++ - Explanation: Valid numeric characters.
- Input:
80: Count Valid Words 🔴 Hard
- Problem: Read a sentence. Split words. Count the number of words that only contain alphabetic characters (no numbers, no special characters).
- Example:
- Input:
toi hoc code 2h moi ngay! - Output:
3 - Explanation: toi, hoc, code
- Input:
Math & Bit Manipulation (Easy)
81: Reverse Integer 🟢 Easy
- Problem: Read an integer X, print the reversed integer. Note that if it’s negative, the minus sign is preserved.
- Example:
- Input:
-123 - Output:
-321 - Explanation: a^n
- Input:
82: Palindrome Number 🟢 Easy
- Problem: Check if a number X is a palindrome (reads the same backwards as forwards).
- Example:
- Input:
121 - Output:
Yes - Explanation: Check condition logic step by step.
- Input:
83: Prime Factorization 🟢 Easy
- Problem: Read N. Print the prime factorization of N.
- Example:
- Input:
12 - Output:
2 2 3 - Explanation: Print combination logic.
- Input:
84: Check Perfect Square 🟢 Easy
- Problem: A perfect square is the square of an integer. Check if N is a perfect square.
- Example:
- Input:
16 - Output:
Yes - Explanation: Return combination.
- Input:
85: Check Perfect Number 🟢 Easy
- Problem: A perfect number is a positive integer that is equal to the sum of its proper divisors. (e.g.,
6 = 1 + 2 + 3). Check N. - Example:
- Input:
28 - Output:
Yes - Explanation: Math check.
- Input:
86: Count 1 Bits 🟢 Easy
- Problem: Read an integer N. Convert it to binary and count the number of 1 bits (Hamming Weight).
- Example:
- Input:
11 - Output:
3 - Explanation: binary: 1011
- Input:
87: Check Power of 2 🟢 Easy
- Problem: Check if N is a power of 2 (
2^k). Use bit manipulation(n & (n - 1) == 0)or count bits. - Example:
- Input:
16 - Output:
Yes - Explanation: Row sums logic.
- Input:
88: Swap Odd and Even Bits 🟢 Easy
- Problem: Read N. Swap its odd and even bits.
- Example:
- Input:
23 - Output:
43 - Explanation: 10111 -> 101011
- Input:
89: Add Two Numbers Without ’+’ 🟢 Easy
- Problem: Add two numbers
a,busing bit manipulation (using^,&, and left shift<<). - Example:
- Input:
1 2 - Output:
3 - Explanation: Diagonal sums logic.
- Input:
90: Single Number 🟢 Easy
- Problem: (Single Number - Leetcode). An array of N elements where every element appears twice except for one. Find that single number.
- Example:
- Input:
4 1 2 1 2 - Output:
4 - Explanation: Determinant logic.
- Input:
Additional Math Fundamentals
91: Calculate Series S = 1/2 + 1/3 + ... + 1/N 🟢 Easy
- Problem: Read N. Calculate S. Print the result rounded to 4 decimal places.
- Example:
- Input:
3 - Output:
0.8333 - Explanation: Inversion logic.
- Input:
92: Double Factorial 🟢 Easy
- Problem:
N!! = 1 * 3 * 5 * ... * N(if N is odd) or2 * 4 * 6 * ... * N(if N is even). - Example:
- Input:
5 - Output:
15 - Explanation: Dictionary usage for frequency.
- Input:
93: Leap Year with Bit Manipulation 🟢 Easy
- Problem: Apply bitwise AND to check divisibility by 4. However, leap years are more complex. (Practice checking using regular if-else or modulo).
- Example:
- Input:
2000 - Output:
Yes - Explanation: Sorting logic.
- Input:
94: Angle Between Clock Hands 🟢 Easy
- Problem: Given the hour
hand minutem. Calculate the angle formed by the two hands on a clock. (Round to 1 decimal place). - Example:
- Input:
3 00 - Output:
90.0 - Explanation: Sorting logic.
- Input:
95: Armstrong Number 🟢 Easy
- Problem: An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits. (e.g.,
153 = 1^3 + 5^3 + 3^3). Check N. - Example:
- Input:
153 - Output:
Yes - Explanation: Check palindrome.
- Input:
96: Days in a Month 🟢 Easy
- Problem: Read a month and a year. Print the number of days in that month.
- Example:
- Input:
2 2024 - Output:
29 - Explanation: Check sequence.
- Input:
97: Sum of Odd Digits 🟢 Easy
- Problem: Read N. Calculate the sum of its odd digits.
- Example:
- Input:
13524 - Output:
9 - Explanation: 1+3+5
- Input:
98: Collatz Sequence 🟢 Easy
- Problem: Start with N. If even,
N=N/2. If odd,N=N*3+1. Repeat until N becomes 1. Print the length of the Collatz sequence. - Example:
- Input:
5 - Output:
6 - Explanation: 5 -> 16 -> 8 -> 4 -> 2 -> 1, length 6
- Input:
99: Modular Exponentiation 🟢 Easy
- Problem: Calculate
(X^Y) % M. Use the Fast Exponentiation algorithm. - Example:
- Input:
X = 2, Y = 3, M = 5 - Output:
3 - Explanation: Mod logic.
- Input:
100: Hamming Distance 🟢 Easy
- Problem: Read two numbers x, y. The Hamming distance is the number of bit positions in which the two bits are different. (Use XOR
x^ythen count 1 bits). - Example:
- Input:
1 4 - Output:
2 - Explanation: 001 and 100 have 2 different bits
- Input:
Hash Map / Set (Easy)
101: Two Sum 🟢 Easy
- Problem: (Leetcode 1) Use a Hash Map to find 2 numbers in an array that add up to a Target. Print the (0-indexed) indices of the two numbers.
- Example:
- Input:
A = [2, 7, 11, 15], Target = 9 - Output:
0 1 - Explanation: A[0] + A[1] = 9
- Input:
102: Contains Duplicate 🟢 Easy
- Problem: (Leetcode 217) Check if any value appears at least twice in the array. Use a Set.
- Example:
- Input:
1 2 3 1 - Output:
Yes - Explanation: Swap digits using formula (n % 10) * 10 + n // 10.
- Input:
103: Intersection of Two Arrays 🟢 Easy
- Problem: (Leetcode 349) Given 2 arrays. Find their intersection (unique elements common to both).
- Example:
- Input:
A = 1 2 2 1, B = 2 2 - Output:
2 - Explanation: Add corresponding elements of two matrices.
- Input:
104: Majority Element 🟢 Easy
- Problem: (Leetcode 169) Find the majority element that appears more than
n/2times in an array of size n. - Example:
- Input:
3 2 3 - Output:
3 - Explanation: Subtract corresponding elements of two matrices.
- Input:
105: Find Disappeared Numbers 🟢 Easy
- Problem: (Leetcode 448) An array of
nelements, with values from1ton. Find all numbers from1tonthat do not appear in the array. - Example:
- Input:
4 3 2 7 8 2 3 1 (n=8) - Output:
5 6 - Explanation: Compute the dot product of rows and columns.
- Input:
106: First Non-Repeating Character 🟢 Easy
- Problem: Similar to exercise 74, use a Hash Map to count character frequencies, then scan the string again to find the first character with a frequency of 1.
- Example:
- Input:
loveleetcode - Output:
2 - Explanation: character ‘v’
- Input:
107: Ransom Note 🟢 Easy
- Problem: (Leetcode 383) Given 2 strings
ransomNoteandmagazine. Check ifransomNotecan be constructed by using the letters frommagazine(each letter can only be used once). - Example:
- Input:
ransomNote = "aa", magazine = "aab" - Output:
Yes - Explanation: Rotate the matrix by 90 degrees clockwise.
- Input:
108: K-diff Pairs in an Array 🟢 Easy
- Problem: Find the number of unique pairs (A[i], A[j]) in an array such that
|A[i] - A[j]| = K. (Easier with a Hash Map / Set). - Example:
- Input:
A = [3, 1, 4, 1, 5], k = 2 - Output:
2 - Explanation: pairs 1-3 and 3-5
- Input:
109: Word Pattern 🟢 Easy
- Problem: (Leetcode 290) Given a
patternand a strings. Ensure each character inpatternmaps to exactly one unique word ins, and vice-versa. - Example:
- Input:
pattern = "abba", s = "dog cat cat dog" - Output:
Yes - Explanation: Binary search on sorted array.
- Input:
110: Word Frequency 🟢 Easy
- Problem: Read a sentence. Count the frequency of each word (case-insensitive).
- Example:
- Input:
Hello hello world - Output:
hello: 2, world: 1 - Explanation: Compare elements step by step.
- Input:
Search & Sort (Easy)
111: Binary Search 🟢 Easy
- Problem: (Leetcode 704) Implement basic binary search to find number
Xin a sorted array. Return index or -1. - Example:
- Input:
A = [-1, 0, 3, 5, 9, 12], X = 9 - Output:
4 - Explanation: Using bubble sort logic to repeatedly swap adjacent elements.
- Input:
112: Basic Bubble Sort 🟢 Easy
- Problem: Sort an integer array in ascending order using Bubble Sort. Print the sorted array.
- Example:
- Input:
5 2 9 1 5 6 - Output:
1 2 5 5 6 9 - Explanation: Find the minimum element and swap it with the first unsorted position.
- Input:
113: Basic Selection Sort 🟢 Easy
- Problem: Implement Selection Sort to sort in descending order.
- Example:
- Input:
5 2 9 1 - Output:
9 5 2 1 - Explanation: Insert each element into its correct sorted position.
- Input:
114: Basic Insertion Sort 🟢 Easy
- Problem: Sort an array in ascending order using Insertion Sort.
- Example:
- Input:
4 3 2 10 12 1 5 6 - Output:
1 2 3 4 5 6 10 12 - Explanation: Quick find using HashMap/HashSet structure.
- Input:
115: Search Insert Position 🟢 Easy
- Problem: (Leetcode 35) Given a sorted array. Find
X. Return its index if found. If not, return the index where it would be if it were inserted in order. - Example:
- Input:
A = [1, 3, 5, 6], X = 5 - Output:
2, Input: A = [1, 3, 5, 6], X = 2 => Output: 1 - Explanation: Build a list of overlapping segments.
- Input:
116: Kth Largest Element 🟢 Easy
- Problem: (Easy, small array) Sort the array and print the Kth largest element (do not use built-in Sort function for small K, or use sorting directly).
- Example:
- Input:
A = [3, 2, 1, 5, 6, 4], K = 2 - Output:
5 - Explanation: Divide the list recursively and merge sorted halves.
- Input:
117: Sort Characters in a String 🟢 Easy
- Problem: Given a string. Sort the characters in lexicographical order (A-Z).
- Example:
- Input:
edcba - Output:
abcde - Explanation: Partition array around a pivot element and sort recursively.
- Input:
118: Check Binary Search Tree Array 🟢 Easy
- Problem: Warm-up: Check if an array can form a valid Binary Search Tree (essentially checking if the array is sorted in ascending order).
- Example:
- Input:
1 2 3 4 - Output:
Yes - Explanation: Calculate combinations using factorial formula C(n, k) = n! / (k! * (n-k)!).
- Input:
119: Missing Number (using sorting) 🟢 Easy
- Problem: Sort the array, then from
i=0toi=n, return the first index whereA[i] != i. - Example:
- Input:
3 0 1 => Missing element is 2 - Output:
2 - Explanation: Convert infix (A+B) to postfix (AB+).
- Input:
120: Perfect Square via Binary Search 🟢 Easy
- Problem: (Leetcode 367) Given
N. Return True ifN = x^2for an integerx. Use Binary Search from 1 to N. - Example:
- Input:
16 - Output:
Yes - Explanation: Evaluate values sequentially based on operators.
- Input:
Stack & Queue (Easy)
(Prerequisite: create Push, Pop, Peek, isEmpty functions or use built-in Collections)
121: Valid Parentheses 🟢 Easy
- Problem: (Leetcode 20) Given a string containing
(),{},[]. Check if the pairs of brackets are valid using a Stack. - Example:
- Input:
()[]{} - Output:
Yes - Explanation: Implement LIFO using an array or list.
- Input:
122: Implement Stack using Array/List 🟢 Easy
- Problem: Implement Push and Pop operations, and print the top of the Stack.
- Example:
- Input:
Push(1), Push(2), Pop(), Print Top - Output:
1 - Explanation: Implement FIFO using an array or list.
- Input:
123: Remove All Adjacent Duplicates In String 🟢 Easy
- Problem: (Leetcode 1047) Remove identical adjacent characters in a string until no such adjacent characters exist (Use Stack).
- Example:
- Input:
abbaca - Output:
ca - Explanation: ab[ba]ca -> a[aa]ca -> ca
- Input:
124: Implement Queue using Stacks 🟢 Easy
- Problem: (Leetcode 232) Build a Queue (Enqueue, Dequeue) using 2 basic Stacks.
- Example:
- Input:
Push(1), Push(2), Pop() - Output:
1 - Explanation: Print tree nodes starting from left, then root, then right.
- Input:
125: Postfix Expression Evaluation (Easy) 🟢 Easy
- Problem: Evaluate Reverse Polish Notation (RPN). Includes only positive numbers and
+,-,*,/. - Example:
- Input:
2 1 + 3 * - Output:
9 (which means (2+1)*3) - Explanation: Print tree nodes starting from left, right, then root.
- Input:
126: Backspace String Compare (via Stack) 🟢 Easy
- Problem: Use a Stack to solve Exercise 68. Overwrite with Pop when hitting
#. Compare the final strings. - Example:
- Input:
ab#c - Output:
ac - Explanation: A node points to next node.
- Input:
127: Printer Queue 🟢 Easy
- Problem: Simulate document printing. Jobs have names and page counts. Sequentially dequeue jobs, subtract 5 pages, if not finished, put them back at the end of the Queue. Calculate the total rounds needed.
- Example:
- Input:
Job A: 6 pages, Job B: 2 pages - Output:
3 rounds (A prints 5 -> B prints 2 (done) -> A prints remaining 1). - Explanation: A node has prev and next pointers.
- Input:
128: String Reversal via Stack 🟢 Easy
- Problem: The basic concept of a Stack is LIFO (Last In First Out). Reverse a string using a Stack. Push all characters and pop to form a new string.
- Example:
- Input:
abc - Output:
cba - Explanation: Traverse the linked list up to N-th node.
- Input:
129: Browser History 🟢 Easy
- Problem: Simulate web browsing forward/backward with 2 Stacks
back_stackandforward_stack. Commands:VISIT url,BACK,FORWARD. - Example:
- Input:
VISIT google -> VISIT facebook -> BACK -> Print URL - Output:
google - Explanation: Change next pointers from end to start.
- Input:
130: Reverse Second Half of a Queue 🟢 Easy
- Problem: Given 1 Queue of even length N. Reverse the second half of the queue and append it.
- Example:
- Input:
1 2 3 4 - Output:
1 2 4 3 - Explanation: Add 1 -> 2 -> 3 + 4 -> 5 -> 6 element by element.
- Input:
Linked List (Easy)
(Requires defining class Node, or mocking it with arrays to practice Next Pointer logic)
131: Create and Print Linked List 🟢 Easy
- Problem: Create a singly linked list with N values (Next Node points to the next number, the last Node points to
null). Print the values. - Example:
- Input:
Input Array: 1, 2, 3 - Output:
1->2->3->null - Explanation: Fast and slow pointers approach.
- Input:
132: Linked List Length 🟢 Easy
- Problem: Write a method that receives the Head of a Linked List and returns the number of Nodes.
- Example:
- Input:
1->3->5 - Output:
Length = 3 - Explanation: Merge lists while comparing head elements.
- Input:
133: Reverse Linked List 🟢 Easy
- Problem: (Leetcode 206) Reverse all
nextreferences of the Linked List. - Example:
- Input:
1->2->3->4->5 - Output:
5->4->3->2->1 - Explanation: Sort the elements using merge sort or an array.
- Input:
134: Merge Two Sorted Linked Lists 🟢 Easy
- Problem: (Leetcode 21) Merge 2 ascending sorted Linked Lists into 1 ascending sorted Linked List.
- Example:
- Input:
1->2->4 and 1->3->4 - Output:
1->1->2->3->4->4 - Explanation: Check if tree has no more than 2 children per node.
- Input:
135: Middle of the Linked List 🟢 Easy
- Problem: (Leetcode 876) Use the 2 pointers method (slow and fast). Fast runs twice as fast. When Fast reaches the end, Slow is in the middle. Print Slow’s value.
- Example:
- Input:
1->2->3->4->5 - Output:
3 - Explanation: Ensure left < root < right.
- Input:
136: Remove Linked List Elements 🟢 Easy
- Problem: (Leetcode 203) Given a value
VAL. Delete all nodes in the Linked List with valueVAL. - Example:
- Input:
1->2->6->3->4->5->6, VAL = 6 - Output:
1->2->3->4->5 - Explanation: Calculate distance from root to deepest leaf.
- Input:
137: Remove Duplicates from Sorted List 🟢 Easy
- Problem: (Leetcode 83) Sorted Linked List. Keep only one instance of each value.
- Example:
- Input:
1->1->2 - Output:
1->2 - Explanation: Return True if structurally identical and values equal.
- Input:
138: Linked List Cycle 🟢 Easy
- Problem: (Leetcode 141) Use the tortoise and hare algorithm (slow and fast pointers). Return boolean indicating whether there is a Cycle.
- Example:
- Input:
3->2->0->-4, Node(-4).next -> Node(2) - Output:
Yes - Explanation: Traverse level by level using a Queue.
- Input:
139: Convert Binary Number in a Linked List to Integer 🟢 Easy
- Problem: (Leetcode 1290) A Linked List describes a binary number (each Node holds 0 or 1). Calculate its integer value in base 10.
- Example:
- Input:
1->0->1 - Output:
5 - Explanation: Find lowest common ancestor in BST.
- Input:
140: Palindrome Linked List 🟢 Easy
- Problem: (Leetcode 234) Check if a Linked List is a palindrome. Solve in O(N) time and O(1) space by finding the Middle, reversing the second half, and comparing with the first half.
- Example:
- Input:
1->2->2->1 - Output:
Yes - Explanation: Traverse array to find path from start to target.
- Input:
Additional Math / Mixed Basics
141: Roman to Integer Part 2 (To Roman) 🟢 Easy
- Problem: Generate a Roman numeral from an integer N (1 to 3999).
- Example:
- Input:
3 - Output:
III, Input: 58 => Output: LVIII - Explanation: Queue based traversal starting from source node.
- Input:
142: Max Consecutive Ones 🟢 Easy
- Problem: Count the maximum number of consecutive 1s in a binary array.
- Example:
- Input:
1,1,0,1,1,1 - Output:
3 - Explanation: Stack based traversal or recursive approach.
- Input:
143: Arithmetic Progression 🟢 Easy
- Problem: Check if an array can form an Arithmetic Progression after sorting.
- Example:
- Input:
3, 5, 1 => Sort -> 1, 3, 5 - Output:
Yes - Explanation: Find shortest path using Dijkstra.
- Input:
144: Count Primes Less Than N 🟢 Easy
- Problem: (Sieve of Eratosthenes - O(N log log N)). Count the number of prime numbers strictly less than
N. - Example:
- Input:
N = 10 - Output:
4 (2, 3, 5, 7) - Explanation: Find minimum spanning tree using Prim’s algorithm.
- Input:
145: Happy Number 🟢 Easy
- Problem: (Leetcode 202). Happy Number. Take N, replace N by the sum of the squares of its digits. If N becomes 1, it’s happy. If it loops endlessly in a cycle not containing 1, print False.
- Example:
- Input:
19 => 1^2 + 9^2 = 82 => ... => 1 - Output:
Yes - Explanation: Find minimum spanning tree using Kruskal’s algorithm.
- Input:
146: Ugly Number 🟢 Easy
- Problem: An ugly number is a positive integer whose prime factors are limited to 2, 3, and 5. Divide N by 2, 3, 5 until N=1.
- Example:
- Input:
6 - Output:
Yes, Input: 14 => Output: No - Explanation: Print characters directly as required.
- Input:
147: Plus One 🟢 Easy
- Problem: (Leetcode 66). An integer array A represents a large integer. Add 1 to this large integer and return the array.
- Example:
- Input:
1,2,3 - Output:
1,2,4., Input: 9,9,9 => Output: 1,0,0,0 - Explanation: Format numerical pattern iteratively.
- Input:
148: Square Root (Sqrt(x)) 🟢 Easy
- Problem: (Leetcode 69) Write Sqrt(x) rounded down to the nearest integer. Do not use any built-in exponent function or operator. Use Binary Search.
- Example:
- Input:
8 - Output:
2 - Explanation: Check boundary conditions before output.
- Input:
149: Find Pivot Index 🟢 Easy
- Problem: Find the pivot index where the sum of all numbers strictly to the left of the index is equal to the sum of all numbers strictly to the index’s right.
- Example:
- Input:
1,7,3,6,5,6 - Output:
3 (since 1+7+3 = 11, 5+6 = 11) - Explanation: Mathematical combinations.
- Input:
150: Valid Parenthesis Sequence 🟢 Easy
- Problem: Easy Parentheses exercise. S only consists of
'('and')'. No Stack needed. Use an up/down counter. - Example:
- Input:
()() - Output:
Yes, Input: ((() => Output: No - Explanation: Count unique combinations.
- Input:
Binary Tree (Easy)
(These problems require defining class TreeNode with val, left, right)
151: Preorder Traversal 🟢 Easy
- Problem: (Leetcode 144) Return the array of values of the Binary Tree following Preorder traversal (Root -> Left -> Right).
- Example:
- Input:
[1,null,2,3] - Output:
1 2 3 - Explanation: Identify peak element by comparing adjacent values.
- Input:
152: Inorder Traversal 🟢 Easy
- Problem: (Leetcode 94) Return the array of values of the Binary Tree following Inorder traversal (Left -> Root -> Right).
- Example:
- Input:
[1,null,2,3] - Output:
1 3 2 - Explanation: Recursively swap string characters to form combinations.
- Input:
153: Postorder Traversal 🟢 Easy
- Problem: (Leetcode 145) Return the array of values following Postorder traversal (Left -> Right -> Root).
- Example:
- Input:
[1,null,2,3] - Output:
3 2 1 - Explanation: Verify character composition recursively.
- Input:
154: Maximum Depth of Binary Tree 🟢 Easy
- Problem: (Leetcode 104) Calculate the maximum depth/height of a Binary Tree.
- Example:
- Input:
[3,9,20,null,null,15,7] - Output:
3 - Explanation: Count recursively to max sum.
- Input:
155: Symmetric Tree 🟢 Easy
- Problem: (Leetcode 101) Check if the Binary Tree is a mirror of itself (i.e., symmetric around its center).
- Example:
- Input:
[1,2,2,3,4,4,3] - Output:
Yes - Explanation: Traverse paths avoiding obstacles.
- Input:
156: Invert Binary Tree 🟢 Easy
- Problem: (Leetcode 226) Invert a binary tree (Swap Left and Right children for all nodes).
- Example:
- Input:
[4,2,7,1,3,6,9] - Output:
[4,7,2,9,6,3,1] - Explanation: Track visited grids dynamically.
- Input:
157: Path Sum 🟢 Easy
- Problem: (Leetcode 112) Check if the tree has a root-to-leaf path such that adding up all the values along the path equals
targetSum. - Example:
- Input:
Sum = 22. Tree = 5->4->11->2 - Output:
5+4+11+2 = 22 - Explanation: Search word in 2D array matrix.
- Input:
158: Same Tree 🟢 Easy
- Problem: (Leetcode 100) Given the roots of two binary trees
pandq. Check if they are structurally identical, and the nodes have the same value. - Example:
- Input:
[1,2,3] and [1,2,3] - Output:
Yes - Explanation: Calculate longest common substring dynamically.
- Input:
159: Search in a Binary Search Tree (BST) 🟢 Easy
- Problem: (Leetcode 700) Given the root of a BST and an integer
val. Find the Node with valuevaland return the subtree rooted with that node. - Example:
- Input:
Tree=[4,2,7,1,3], val=2 - Output:
Return Node 2 (with subtree) - Explanation: Base pattern implementation.
- Input:
160: Convert Sorted Array to Binary Search Tree 🟢 Easy
- Problem: (Leetcode 108) Convert an ascending sorted integer array into a height-balanced BST (Take the middle element as Root, recursively divide in half).
- Example:
- Input:
[-10,-3,0,5,9] - Output:
[0,-3,9,-10,null,5] - Explanation: Advanced pattern implementation.
- Input:
Graph / Matrix / Search Basics (Easy)
161: Convert Graph to Adjacency Matrix 🟢 Easy
- Problem: Write code to read
Eundirected edges of a graph withNvertices. Create anN x NAdjacency Matrix. - Example:
- Input:
Edges (0,1), (0,2) - Output:
Matrix[0][1] = Matrix[1][0] = 1, Matrix[0][2] = Matrix[2][0] = 1 - Explanation: Verify matching conditions mathematically.
- Input:
162: Island Perimeter 🟢 Easy
- Problem: (Leetcode 463) 2D matrix containing 0 (water) and 1 (land). Calculate the perimeter of the island. (Island = cluster of connected 1s).
- Example:
- Input:
, 0 1 0 0, 1 1 1 0, 0 1 0 0 - Output:
16 - Explanation: Filter and reduce string values.
- Input:
163: Flood Fill 🟢 Easy
- Problem: (Leetcode 733) Paint bucket algorithm. Given a matrix, coordinate
(sr, sc), and a newcolor. Replace the original pixel color and all connected adjacent pixels of the same old color. (Use basic DFS or BFS). - Example:
- Input:
image = [[1,1,1],[1,1,0],[1,0,1]], (sr=1, sc=1), color = 2 - Output:
[[2,2,2],[2,2,0],[2,0,1]] - Explanation: Perform quick calculations on sets.
- Input:
164: Count Adjacency Degrees 🟢 Easy
- Problem: Read
Vvertices,Eedges. Calculate the “degree” of all vertices in an undirected graph (Degree = number of connected edges). - Example:
- Input:
Edges (0, 1) (0, 2) - Output:
Degree of vertex 0 is 2, vertex 1 is 1, vertex 2 is 1 - Explanation: Identify overlapping domains.
- Input:
165: Center of Star Graph 🟢 Easy
- Problem: (Leetcode 1791) A Star Graph has 1 central vertex connected to all other vertices. Find the center vertex. Return that vertex.
- Example:
- Input:
Edges (1,2), (2,3), (4,2) - Output:
2 - Explanation: Calculate differences geometrically.
- Input:
Simple Dynamic Programming & Memoization (Easy)
(Practice DP arrays to store subproblem results)
166: Fibonacci Number (DP) 🟢 Easy
- Problem: (Leetcode 509) Calculate
F(N) = F(N-1) + F(N-2). Use a 1D DP array instead of unoptimized recursion.O(N)algorithm. - Example:
- Input:
N = 4 - Output:
3 - Explanation: Format sorting criteria properly.
- Input:
167: Climbing Stairs 🟢 Easy
- Problem: (Leetcode 70) It takes
Nsteps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? (Essentially Fibonacci). - Example:
- Input:
N = 3 - Output:
3 ways (1+1+1, 1+2, 2+1) - Explanation: Use sorting to map occurrences.
- Input:
168: Best Time to Buy and Sell Stock (Easy) 🟢 Easy
- Problem: (Leetcode 121) Given an array of prices. Choose a single day to buy and a different day in the future to sell to maximize profit. (Algorithm: keep track of
min_priceseen so far, updatemax_profit). - Example:
- Input:
[7,1,5,3,6,4] - Output:
5 (buy at 1, sell at 6) - Explanation: Format string sequence algorithmically.
- Input:
169: House Robber 🟢 Easy
- Problem: (Leetcode 198) Houses along a street have money. Robbers cannot rob two adjacent houses. Calculate the maximum amount of money you can rob.
- Example:
- Input:
[1,2,3,1] - Output:
4 (rob 1 and 3) - Explanation: Replace tokens efficiently.
- Input:
170: Pascal’s Triangle 🟢 Easy
- Problem: (Leetcode 118) Given the number of rows
numRows. Generate Pascal’s Triangle up to that row. - Example:
- Input:
numRows = 5 - Output:
[[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]] - Explanation: Output binary structure recursively.
- Input:
171: Pascal’s Triangle II 🟢 Easy
- Problem: (Leetcode 119) Calculate and return only the
rowIndex-th row (0-indexed) of Pascal’s Triangle usingO(K)extra space. - Example:
- Input:
rowIndex = 3 - Output:
[1,3,3,1] - Explanation: Output hex structure recursively.
- Input:
172: Maximum Subarray (Kadane’s Algorithm) 🟢 Easy
- Problem: (Leetcode 53) Array containing positive and negative numbers. Find the contiguous subarray with the largest sum.
- Example:
- Input:
[-2,1,-3,4,-1,2,1,-5,4] - Output:
6 (subarray [4,-1,2,1]) - Explanation: Count recursive depths.
- Input:
173: Min Cost Climbing Stairs 🟢 Easy
- Problem: (Leetcode 746) Given an integer array
costwherecost[i]is the cost of stepi. Once you pay the cost, you can either climb 1 or 2 steps. You can either start from step 0 or step 1. Return the minimum cost to reach the top. - Example:
- Input:
cost = [10, 15, 20] - Output:
15 (start from index 1, pay 15, climb 2 steps to the top) - Explanation: Divide tree logic dynamically.
- Input:
174: Unique Paths (Simplistic Logic) 🟢 Easy
- Problem: (Robot on an
m x ngrid) Can only move down or right. Find the number of possible unique paths to reach the bottom-right cornerm-1, n-1. (Can use Combinatorics or DP). - Example:
- Input:
m=3, n=2 - Output:
3 - Explanation: Trace path outputs.
- Input:
175: Divisor Game 🟢 Easy
- Problem: (Leetcode 1025) Basic mathematical DP. Given N. Players take turns choosing
xwith0 < x < NandN % x == 0, then replaceNwithN - x. A player loses if they cannot make a move. Return True if Alice wins. - Example:
Mathematically: If N is even, Win; if odd, Lose.
Greedy Algorithms (Easy)
176: Assign Cookies 🟢 Easy
- Problem: (Leetcode 455) Given children’s greed factor array
gand cookie size arrays. Each child gets at most 1 cookie wheres[j] >= g[i]. Maximize the number of content children. - Example:
- Input:
g=[1,2,3], s=[1,1] - Output:
1 (Only the child with g=1 gets a cookie). - Explanation: Base math computation loop.
- Input:
177: Best Time to Buy and Sell Stock II 🟢 Easy
- Problem: (Leetcode 122) Can buy and sell multiple times (must sell before buying again). What is the maximum profit?
- Example:
- Input:
[7,1,5,3,6,4] - Output:
7 (Buy at 1, sell at 5 for profit 4. Buy at 3, sell at 6 for profit 3. Total profit = 7). - Explanation: Implement matrix row manipulation.
- Input:
178: Longest Palindrome 🟢 Easy
- Problem: (Leetcode 409) Given a string
scontaining lowercase and uppercase letters. Build the longest possible palindrome using those letters. - Example:
- Input:
s="abccccdd" - Output:
7 ("dccaccd") - Explanation: Filter array sequentially.
- Input:
179: Reduce Array Size to Zero 🟢 Easy
- Problem: Greedily find the minimum positive element. Subtract this minimum from all elements
> 0. Print the non-zero elements. Count the steps required until all elements become0. - Example:
Input: [1, 2, 3] -> (subtract 1) -> [0, 1, 2] -> (subtract 1) -> [0, 0, 1] ... Total 3 steps.
180: Minimum Cost to Connect Sticks 🟢 Easy
- Problem: Not a standard full DP array, but a greedy algorithm to connect ropes/sticks (Basic Priority Queue). Always connect the two smallest pieces together.
Assorted Logic Exercises (From Leetcode)
181: Excel Sheet Column Title 🟢 Easy
- Problem: (Leetcode 168) Given an integer N. Return its corresponding column title as it appears in an Excel sheet. (e.g.,
1=A,2=B,26=Z,27=AA,28=AB…). - Example:
- Input:
N = 28 - Output:
AB - Explanation: Generate output lists dynamically.
- Input:
182: Excel Sheet Column Number 🟢 Easy
- Problem: (Leetcode 171) The reverse of Exercise 181. Given a column title like “AB”, return its corresponding column number. Uses base-26 logic.
- Example:
- Input:
"ZY" - Output:
701 - Explanation: Check condition states.
- Input:
183: Bulls and Cows 🟢 Easy
- Problem: (Leetcode 299) You are playing the Bulls and Cows game. Given
secretandguess. Count the digits in the exact matches (Bulls) and in the wrong position (Cows). - Example:
- Input:
secret="1807", guess="7810" => 1 Bull (8), 3 Cows (1, 0, 7) - Output:
"1A3B" - Explanation: Verify state parameters.
- Input:
184: Convert 1D Array Into 2D Array 🟢 Easy
- Problem: (Leetcode 2022) Given a 1D array
originalof size N. Convert it to a 2D array of sizem x n. Return an empty 2D array ifm * n != N. - Example:
- Input:
original=[1,2,3,4], m=2, n=2 - Output:
[[1,2],[3,4]] - Explanation: Return state sequences.
- Input:
185: Character Frequencies (Ransom Note -> Valid Anagram) 🟢 Easy
- Problem: Practice counting characters. Return a frequency map or an array of frequencies when reading a text. Note: Practice using regex to parse valid words.
186: Factorial Trailing Zeroes 🟢 Easy
- Problem: (Leetcode 172) Return the number of trailing zeroes in
N!. The key is counting how many pairs of 10 (2 * 5) exist, which fundamentally means counting the number of factor 5s. - Example:
- Input:
N=5 - Output:
1 (5! = 120). - Explanation: Output dynamic sequences.
- Input:
187: Array Permutation Check 🟢 Easy
- Problem: Given an array
Array[1..N]. Check if it contains a valid permutation of numbers from1toNcontinuous. Use XOR to solve efficiently.
188: Perfect Cube Check 🟢 Easy
- Problem: A variation of Binary Search from 1 to the cube root of the Maximum Integer. Print Yes/No if the number is a perfect cube.
189: Reverse String in place 🟢 Easy
- Problem: (Leetcode 344) Reverse String
sgiven as an array of characters directly usingO(1)space (In-place). - Example:
- Input:
['h', 'e', 'l', 'l', 'o'] - Output:
['o', 'l', 'l', 'e', 'h'] - Explanation: Compute path distances.
- Input:
190: Reverse Words in a Sentence 🟢 Easy
- Problem: (Leetcode 557) Read a sentence, reverse the order of characters in each word while preserving whitespace. Try not to use
Split. - Example:
- Input:
"Let's take contest" - Output:
"s'teL ekat tsetnoc" - Explanation: Format numerical distances.
- Input:
10 Comprehensive Basic Logic Reviews
191: Water Bottle 🟢 Easy
- Problem: Practice defining a Struct/Class
WaterBottle: has a capacity (ml) and an amount of water inside. Write functions like Fill, Consume, etc. Print the internal state logic after a series of operations.
192: ATM Machine 🟢 Easy
- Problem: Initialize an array of denominations:
[50, 100, 200, 500]. WithdrawNamount. Output the minimum number of notes to dispense the amount. (A practical Greedy Algorithm application).
193: Tic Tac Toe Checking 🟢 Easy
- Problem: Given a
3 x 3Matrix filled with ‘X’ and ‘O’. Check if ‘X’ has won, ‘O’ has won, or if it is a Tie.
194: Defang IP Address 🟢 Easy
- Problem: (Leetcode 1108) Given a valid IPv4 address, return its defanged version. Replace every period
.with[.]. - Example:
- Input:
1.1.1.1 - Output:
1[.]1[.]1[.]1 - Explanation: Test hex combinations.
- Input:
195: String Compression 🟢 Easy
- Problem: (Leetcode 443) Compress
["a","a","b","b","c","c","c"]into["a","2","b","2","c","3"]. Do it in-placeO(1)memory. Return the new length.
196: Sell Connected Items 🟢 Easy
- Problem: A variation of two-pointers. Given a continuous string with multiple segments of
'a'or'b'. Find and extract the largest continuous segment.
197: Matrix Reshape 🟢 Easy
- Problem: Given an
M x Nmatrix, reshape it to sequentially populate a newR x Cmatrix. Output an error or return the original matrix if the total number of elementsM*Ndoes not matchR*C.
198: Birthday Paradox Simulation 🟢 Easy
- Problem: Initialize an array of 365 days. Randomize
Kpeople’s birthdays. Practice simulation, hashing, and probability lists to see how often two people share the same birthday.
199: Keyboard Row 🟢 Easy
- Problem: (Leetcode 500). The US Keyboard has 3 rows: R1(
qwertyuiop), R2(asdfghjkl), R3(zxcvbnm). Given a list of words, return only the words that can be typed using characters on the same row.
200: Max Format Time 🟢 Easy
- Problem: Given 4 random digits (e.g.,
[1, 2, 3, 4]). Build the latest possible valid time string inHH:MMformat. If no valid time can be formed, print"".
Arrays & Hashing (Medium)
201: Group Anagrams 🟡 Medium
- Problem: (Leetcode 49) Given an array of strings, group the anagrams together. Anagrams are strings that contain the exact same characters but in different orders.
- Example:
- Input:
["eat","tea","tan","ate","nat","bat"] - Output:
[["bat"],["nat","tan"],["ate","eat","tea"]] - Explanation: Start from bottom right, min path to (0,0).
- Input:
202: Top K Frequent Elements 🟡 Medium
- Problem: (Leetcode 347) Given an integer array
numsand an integerk, return thekmost frequent elements. - Example:
- Input:
nums = [1,1,1,2,2,3], k = 2 - Output:
[1, 2] - Explanation: Recursive combination logic starting from index 0.
- Input:
203: Product of Array Except Self 🟡 Medium
- Problem: (Leetcode 238) Given an integer array
nums, return an arrayanswersuch thatanswer[i]is equal to the product of all the elements ofnumsexceptnums[i]. You must write an algorithm that runs inO(N)time and without using the division operation. - Example:
- Input:
nums = [1,2,3,4] - Output:
[24,12,8,6] - Explanation:
answer[0] = 2*3*4 = 24
- Input:
204: Longest Consecutive Sequence 🟡 Medium
- Problem: (Leetcode 128) Given an unsorted array of integers
nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs inO(N)time. - Example:
- Input:
nums = [100,4,200,1,3,2] - Output:
4 (The longest consecutive sequence is [1,2,3,4]). - Explanation: Include uniqueness filter to combinations.
- Input:
205: Valid Sudoku 🟡 Medium
- Problem: (Leetcode 36) Determine if a
9x9Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row, column, and3x3sub-box must contain the digits1-9without repetition. - Example:
- Input:
A board with duplicate '5's in the same 3x3 block - Output:
False. - Explanation: Generate permutations iteratively.
- Input:
206: Encode and Decode Strings 🟡 Medium
- Problem: (Leetcode 271) Design an algorithm to encode a list of strings to a single string, and then decode the single string back to the original list of strings.
- Example:
- Input:
["lint","code","love","you"] - Output:
"4#lint4#code4#love3#you" - Explanation: Use HashSet to avoid duplicate permutations.
- Input:
207: Rotate Image 🟡 Medium
- Problem: (Leetcode 48) You are given an
N x N2D matrix representing an image. Rotate the image by 90 degrees (clockwise). You have to rotate the image in-place. - Example:
[[1,2,3], [[7,4,1], [4,5,6], => [8,5,2], [7,8,9]] [9,6,3]]
208: First Missing Positive 🟡 Medium
- Problem: (Leetcode 41) Given an unsorted integer array
nums, return the smallest missing positive integer. You must implement an algorithm that runs inO(N)time and usesO(1)auxiliary space. - Example:
- Input:
nums = [3,4,-1,1] - Output:
2 - Explanation: Track valid parentheses combinations recursively.
- Input:
209: Spiral Matrix 🟡 Medium
- Problem: (Leetcode 54) Given an
m x nmatrix, return all elements of thematrixin spiral order. - Example:
- Input:
[[1,2,3],[4,5,6],[7,8,9]] - Output:
[1,2,3,6,9,8,7,4,5] - Explanation: Backtracking search starting from empty string.
- Input:
210: Set Matrix Zeroes 🟡 Medium
- Problem: (Leetcode 73) Given an
m x ninteger matrixmatrix, if an element is0, set its entire row and column to0’s. You must do it in place. - Example:
[[1,1,1], [[1,0,1], [1,0,1], => [0,0,0], [1,1,1]] [1,0,1]]
Two Pointers (Medium)
211: 3Sum 🟡 Medium
- Problem: (Leetcode 15) Given an integer array
nums, return all the triplets[nums[i], nums[j], nums[k]]such thati != j,i != k, constraintsj != k, and their sum is0. The solution set must not contain duplicate triplets. - Example:
- Input:
nums = [-1,0,1,2,-1,-4] - Output:
[[-1,-1,2],[-1,0,1]] - Explanation: Convert map mappings functionally.
- Input:
212: Container With Most Water 🟡 Medium
- Problem: (Leetcode 11) You are given an integer array
heightof lengthn. There arenvertical lines drawn such that the two endpoints of thei-thline are(i, 0)and(i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. - Example:
- Input:
height = [1,8,6,2,5,4,8,3,7] - Output:
49 (Lines at index 1 and index 8 form a container of width 7 and height 7 - Explanation: Evaluate matrix constraints.
- Input:
213: Two Sum II - Input Array Is Sorted 🟡 Medium
- Problem: (Leetcode 167) Given a 1-indexed array of integers
numbersthat is already sorted in non-decreasing order, find two numbers such that they add up to a specifictargetnumber. Return the indices of the two numbers. - Example:
- Input:
numbers = [2,7,11,15], target = 9 - Output:
[1, 2] - Explanation: Traverse tree recursively tracking depth.
- Input:
214: Valid Palindrome 🟡 Medium
- Problem: (Leetcode 125) 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. Given a string
s, returntrueif it is a palindrome. - Example:
- Input:
s = "A man, a plan, a canal: Panama" - Output:
True ("amanaplanacanalpanama"). - Explanation: Construct list nodes algorithmically.
- Input:
215: Trapping Rain Water 🟡 Medium
- Problem: (Leetcode 42) Given
nnon-negative integers representing an elevation map where the width of each bar is1, compute how much water it can trap after raining. Use two pointers withO(1)space for maximum efficiency. - Example:
- Input:
height = [0,1,0,2,1,0,1,3,2,1,2,1] - Output:
6 - Explanation: Evaluate array subset differences.
- Input:
216: Sort Colors 🟡 Medium
- Problem: (Leetcode 75) Given an array
numswithnobjects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue. We will use the integers0,1, and2to represent the color red, white, and blue, respectively. You must solve this problem without using the library’s sort function in a single pass. - Example:
- Input:
nums = [2,0,2,1,1,0] - Output:
[0,0,1,1,2,2] - Explanation: Combine map structures dynamically.
- Input:
217: Squares of a Sorted Array 🟡 Medium
- Problem: (Leetcode 977) Given an integer array
numssorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. - Example:
- Input:
nums = [-4,-1,0,3,10] - Output:
[0,1,9,16,100] - Explanation: Partition list logically.
- Input:
218: Remove Nth Node From End of List 🟡 Medium
- Problem: (Leetcode 19) Given the
headof a linked list, remove then-thnode from the end of the list and return its head. Follow up: Could you do this in one pass? - Example:
- Input:
head = [1,2,3,4,5], n = 2 - Output:
[1,2,3,5] - Explanation: Iterate while filtering matching patterns.
- Input:
219: Reverse Words in a String 🟡 Medium
- Problem: (Leetcode 151) Given an input string
s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words inswill be separated by at least one space. Output should not contain leading or trailing spaces or multiple spaces between words. - Example:
- Input:
s = " hello world " - Output:
"world hello" - Explanation: Build prefix strings functionally.
- Input:
220: Sort Array By Parity 🟡 Medium
- Problem: (Leetcode 905) Given an integer array
nums, move all the even integers at the beginning of the array followed by all the odd integers. - Example:
- Input:
nums = [3,1,2,4] - Output:
[2,4,3,1] - Explanation: Sum tree node paths iteratively.
- Input:
Sliding Window (Medium)
221: Longest Substring Without Repeating Characters 🟡 Medium
- Problem: (Leetcode 3) Given a string
s, find the length of the longest substring without repeating characters. - Example:
- Input:
s = "abcabcbb" - Output:
3 ("abc"). - Explanation: Compare binary tree structures.
- Input:
222: Longest Repeating Character Replacement 🟡 Medium
- Problem: (Leetcode 424) You are given a string
sand an integerk. You can choose any character of the string and change it to any other uppercase English character. You can perform this operation at mostktimes. Return the length of the longest substring containing the same letter you can get after performing the above operations. - Example:
- Input:
s = "ABAB", k = 2 - Output:
4 ("BBBB" or "AAAA"). - Explanation: Evaluate boolean matrix fields.
- Input:
223: Permutation in String 🟡 Medium
- Problem: (Leetcode 567) Given two strings
s1ands2, returntrueifs2contains a permutation ofs1, orfalseotherwise. - Example:
- Input:
s1 = "ab", s2 = "eidbaooo" - Output:
True ("ba" is a permutation of "ab"). - Explanation: Find consecutive patterns algorithmically.
- Input:
224: Sliding Window Maximum 🟡 Medium
- Problem: (Leetcode 239) You are given an array of integers
nums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. - Example:
- Input:
nums = [1,3,-1,-3,5,3,6,7], k = 3 - Output:
[3,3,5,5,6,7] - Explanation: Count sequential numeric increments.
- Input:
225: Subarray Sum Equals K 🟡 Medium
- Problem: (Leetcode 560) Given an array of integers
numsand an integerk, return the total number of subarrays whose sum equals tok. A subarray is a contiguous non-empty sequence of elements within an array. - Example:
- Input:
nums = [1,1,1], k = 2 - Output:
2 - Explanation: Reverse linked list segments.
- Input:
226: Subarray Product Less Than K 🟡 Medium
- Problem: (Leetcode 713) Given an array of integers
numsand an integerk, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less thank. - Example:
- Input:
nums = [10,5,2,6], k = 100 - Output:
8 - Explanation: Sum consecutive overlapping pairs.
- Input:
227: Substring with Concatenation of All Words 🟡 Medium
- Problem: (Leetcode 30) You are given a string
sand an array of stringswords. All the strings ofwordsare of the same length. Find all starting indices of substring(s) insthat is a concatenation of each word inwordsexactly once and without any intervening characters. - Example:
- Input:
s = "barfoothefoobarman", words = ["foo","bar"] - Output:
[0, 9] - Explanation: Calculate subset variances.
- Input:
228: Fruit Into Baskets 🟡 Medium
- Problem: (Leetcode 904) You have two baskets, and each basket can only hold a single type of fruit. You must pick exactly one fruit from every tree (including the start tree) while moving to the right. If you reach a tree with fruit that cannot fit in your baskets, you must stop. Return the maximum number of fruits you can pick.
- Example:
- Input:
fruits = [1,2,1,3,4] - Output:
3 - Explanation:
[1, 2, 1]
- Input:
229: Find All Anagrams in a String 🟡 Medium
- Problem: (Leetcode 438) Given two strings
sandp, return an array of all the start indices ofp’s anagrams ins. - Example:
- Input:
s = "cbaebabacd", p = "abc" - Output:
[0, 6] - Explanation: Match prefix sets logically.
- Input:
230: Minimum Window Substring 🟡 Medium
- Problem: (Leetcode 76) Given two strings
sandtof lengthsmandnrespectively, return the minimum window substring ofssuch that every character int(including duplicates) is included in the window. If there is no such substring, return the empty string"". - Example:
- Input:
s = "ADOBECODEBANC", t = "ABC" - Output:
"BANC" - Explanation: Extract maximum subset configurations.
- Input:
Stack & Queue (Medium)
231: Evaluate Reverse Polish Notation 🟡 Medium
- Problem: (Leetcode 150) Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are
+,-,*, and/. Each operand may be an integer or another expression. Division between two integers should truncate toward zero. - Example:
- Input:
tokens = ["10","6","9","3","+","-11","*","/","*","17","+","5","+"] - Output:
22 - Explanation: Implement DP caching for performance.
- Input:
232: Daily Temperatures 🟡 Medium
- Problem: (Leetcode 739) Given an array of integers
temperaturesrepresents the daily temperatures, return an arrayanswersuch thatanswer[i]is the number of days you have to wait after thei-thday to get a warmer temperature. If there is no future day for which this is possible, keepanswer[i] == 0instead. - Example:
- Input:
temperatures = [73,74,75,71,69,72,76,73] - Output:
[1,1,4,2,1,1,0,0] - Explanation: Sum integer components iteratively.
- Input:
233: Generate Parentheses 🟡 Medium
- Problem: (Leetcode 22) Given
npairs of parentheses, write a function to generate all combinations of well-formed parentheses. - Example:
- Input:
n = 3 - Output:
["((()))","(()())","(())()","()(())","()()()"] - Explanation: Evaluate character offsets logically.
- Input:
234: Basic Calculator II 🟡 Medium
- Problem: (Leetcode 227) Given a string
swhich represents an expression, evaluate this expression and return its value. The integer division should truncate toward zero. You may assume that the given expression is always valid. All intermediate results will be in the range of[-2^31, 2^31 - 1]. The expression contains only non-negative integers,+,-,*,/operators and empty spaces. - Example:
- Input:
s = " 3+5 / 2 " - Output:
5 - Explanation: Filter redundant objects.
- Input:
235: Car Fleet 🟡 Medium
- Problem: (Leetcode 853) There are
ncars going to the same destination along a one-lane road. The destination istargetmiles away. You are given two integer arraypositionandspeed. A car can never pass another car ahead of it, but it can catch up to it and drive bumper to bumper at the same speed. The faster car will slow down to match the slower car’s speed. Find how many car fleets will arrive at the destination. - Example:
- Input:
target = 12, position = [10,8,0,5,3], speed = [2,4,1,1,3] - Output:
3 - Explanation: Format numeric arrays logically.
- Input:
236: Largest Rectangle in Histogram 🟡 Medium
- Problem: (Leetcode 84) Given an array of integers
heightsrepresenting the histogram’s bar height where the width of each bar is1, return the area of the largest rectangle in the histogram. - Example:
- Input:
heights = [2,1,5,6,2,3] - Output:
10 - Explanation: Extract deep structured paths.
- Input:
237: Next Greater Element II 🟡 Medium
- Problem: (Leetcode 503) Given a circular integer array
nums(i.e., the next element ofnums[nums.length - 1]isnums[0]), return the next greater number for every element innums. - Example:
- Input:
nums = [1,2,1] - Output:
[2,-1,2] - Explanation: Calculate multi-dimensional matrices.
- Input:
238: Asteroid Collision 🟡 Medium
- Problem: (Leetcode 735) We are given an array
asteroidsof integers representing asteroids in a row. For each asteroid, the absolute value represents its size, and the sign represents its direction. Find out the state of the asteroids after all collisions. - Example:
- Input:
asteroids = [5,10,-5] - Output:
[5,10] - Explanation: Process queue logic sequentially.
- Input:
239: Decode String 🟡 Medium
- Problem: (Leetcode 394) Given an encoded string, return its decoded string. The encoding rule is:
k[encoded_string], where theencoded_stringinside the square brackets is being repeated exactlyktimes. - Example:
- Input:
s = "3[a2[c]]" - Output:
"accaccacc" - Explanation: Process stack algorithms LIFO.
- Input:
240: Remove K Digits 🟡 Medium
- Problem: (Leetcode 402) Given string
numrepresenting a non-negative integernum, and an integerk, return the smallest possible integer after removingkdigits fromnum. - Example:
- Input:
num = "1432219", k = 3 - Output:
"1219" - Explanation: Traverse bidirectional lists.
- Input:
Advanced Binary Search (Medium)
241: Search in Rotated Sorted Array 🔴 Hard
- Problem: (Leetcode 33) There is an integer array
numssorted in ascending order (with distinct values). Prior to being passed to your function,numsis possibly rotated at an unknown pivot index. Given the arraynumsafter the possible rotation and an integertarget, return the index oftargetif it is innums, or-1if it is not innums. You must write an algorithm withO(log n)runtime complexity. - Example:
- Input:
nums = [4,5,6,7,0,1,2], target = 0 - Output:
4 - Explanation: Calculate shortest paths procedurally.
- Input:
242: Find Minimum in Rotated Sorted Array 🔴 Hard
- Problem: (Leetcode 153) Suppose an array of length
nsorted in ascending order is rotated between1andntimes. Given the sorted rotated arraynumsof unique elements, return the minimum element of this array. You must write an algorithm that runs inO(log n)time. - Example:
- Input:
nums = [3,4,5,1,2] - Output:
1 - Explanation: Find lowest common factors dynamically.
- Input:
243: Search a 2D Matrix 🔴 Hard
- Problem: (Leetcode 74) You are given an
m x ninteger matrixmatrixwith the following two properties: Each row is sorted in non-decreasing order. The first integer of each row is greater than the last integer of the previous row. Given an integertarget, returntrueiftargetis inmatrixorfalseotherwise. - Example:
- Input:
matrix = [[1,3,5,7],[10,11,16,20],[23,30,34,60]], target = 3 - Output:
true - Explanation: Parse structural strings iteratively.
- Input:
244: Koko Eating Bananas 🔴 Hard
- Problem: (Leetcode 875) Koko loves to eat bananas. There are
npiles of bananas, thei-thpile haspiles[i]bananas. The guards have gone and will come back inhhours. Koko can decide her bananas-per-hour eating speed ofk. Return the minimum integerksuch that she can eat all the bananas withinhhours. - Example:
- Input:
piles = [3,6,7,11], h = 8 - Output:
4 - Explanation: Reverse numerical limits securely.
- Input:
245: Capacity To Ship Packages Within D Days 🔴 Hard
- Problem: (Leetcode 1011) A conveyor belt has packages that must be shipped from one port to another within
daysdays. Returns the least weight capacity of the ship that will result in all the packages on the conveyor belt being shipped withindaysdays. - Example:
- Input:
weights = [1,2,3,4,5,6,7,8,9,10], days = 5 - Output:
15 - Explanation: Detect sequential cyclic patterns.
- Input:
246: Minimum Number of Days to Make m Bouquets 🔴 Hard
- Problem: (Leetcode 1482) You are given an integer array
bloomDay, an integermand an integerk. You want to makembouquets. To make a bouquet, you need to usekadjacent flowers from the garden. Return the minimum number of days you need to wait to be able to makembouquets from the garden. If it is impossible, return-1. - Example:
- Input:
bloomDay = [1,10,3,10,2], m = 3, k = 1 - Output:
3 - Explanation: Merge variable overlapping lists.
- Input:
247: Split Array Largest Sum 🔴 Hard
- Problem: (Leetcode 410) Given an integer array
numsand an integerk, splitnumsintoknon-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. - Example:
- Input:
nums = [7,2,5,10,8], k = 2 - Output:
18 - Explanation: Compute geometric boundaries algorithmically.
- Input:
248: Peak Index in a Mountain Array 🔴 Hard
- Problem: (Leetcode 852) An array
arris a mountain if it is strictly increasing until a peak, then strictly decreasing. Given a mountain arrayarr, return the index of the peak element. You must solve it inO(log(arr.length))time complexity. - Example:
- Input:
arr = [0,2,1,0] - Output:
1 - Explanation: Find maximum sequential changes using binary search.
- Input:
249: Find First and Last Position of Element in Sorted Array 🔴 Hard
- Problem: (Leetcode 34) Given an array of integers
numssorted in non-decreasing order, find the starting and ending position of a giventargetvalue. Iftargetis not found in the array, return[-1, -1]. You must write an algorithm withO(log n)runtime complexity. - Example:
- Input:
nums = [5,7,7,8,8,10], target = 8 - Output:
[3, 4] - Explanation: Identify bounds within ordered sets using binary search.
- Input:
250: Search a 2D Matrix II 🔴 Hard
- Problem: (Leetcode 240) Write an efficient algorithm that searches for a value
targetin anm x ninteger matrixmatrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in each column are sorted in ascending from top to bottom. - Example:
- Input:
matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22]], target = 5 - Output:
true - Explanation: Use divide and conquer in structured matrix spaces.
- Input:
Linked List (Medium)
251: LRU Cache 🟡 Medium
- Problem: (Leetcode 146) Design a data structure that follows the constraints of a Least Recently Used (LRU) cache. Implement the
LRUCacheclass with methodsget(key)andput(key, value). The functionsgetandputmust each run inO(1)average time complexity. - Example:
- Input:
put(1, 1), put(2, 2), get(1) - Output:
1, put(3, 3), get(2) - Explanation: evicted
- Input:
252: Add Two Numbers 🟡 Medium
- Problem: (Leetcode 2) 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.
- Example:
- Input:
l1 = [2,4,3], l2 = [5,6,4] - Output:
[7,0,8] - Explanation: Track sequence distributions.
- Input:
253: Copy List with Random Pointer 🟡 Medium
- Problem: (Leetcode 138) A linked list of length
nis given such that each node contains an additional random pointer, which could point to any node in the list, ornull. Construct a deep copy of the list. - Example:
- Input:
head = [[7,null], [13,0], [11,4], [10,2], [1,0]](Pairs of[val, random_index]) - Output: Returns a completely new deep copied linked list.
- Explanation: O(N) memory approach: Use a Hash Map to map
Original Node -> Copied Nodein the first pass. Second pass linksnextandrandom. O(1) memory approach: Insert copied nodes directly after their original counterparts (A -> A' -> B -> B'), setrandompointers for copies, and then separate the two lists.
- Input:
254: Linked List Cycle II 🟡 Medium
- Problem: (Leetcode 142) Given the head of a linked list, return the node where the cycle begins. If there is no cycle, return
null. There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. - Example:
- Input:
head = [3,2,0,-4], pos = 1 - Output:
2 - Explanation: Evaluate structured lists concurrently.
- Input:
255: Rotate List 🟡 Medium
- Problem: (Leetcode 61) Given the head of a linked list, rotate the list to the right by
kplaces. - Example:
- Input:
head = [1,2,3,4,5], k = 2 - Output:
[4,5,1,2,3] - Explanation: Trace cyclic linked paths.
- Input:
256: Odd Even Linked List 🟡 Medium
- Problem: (Leetcode 328) Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. You must solve the problem in
O(1)extra space complexity andO(n)time complexity. - Example:
- Input:
head = [1,2,3,4,5] - Output:
[1,3,5,2,4] - Explanation: Format consecutive array elements dynamically.
- Input:
257: Intersection of Two Linked Lists 🟡 Medium
- Problem: (Leetcode 160) Given the heads of two singly linked-lists
headAandheadB, return the node at which the two lists intersect. If the two linked lists have no intersection at all, returnnull. - Example:
- Input:
listA = [4,1,8,4,5], listB = [5,6,1,8,4,5] - Output:
8 - Explanation: Find maximum product subarrays logically.
- Input:
258: Remove Duplicates from Sorted List II 🟡 Medium
- Problem: (Leetcode 82) Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
- Example:
- Input:
head = [1,2,3,3,4,4,5] - Output:
[1,2,5] - Explanation: Evaluate minimal sequence structures.
- Input:
259: Swap Nodes in Pairs 🟡 Medium
- Problem: (Leetcode 24) Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list’s nodes (i.e., only nodes themselves may be changed.)
- Example:
- Input:
head = [1,2,3,4] - Output:
[2,1,4,3] - Explanation: Track overlapping subsets dynamically.
- Input:
260: Sort List 🟡 Medium
- Problem: (Leetcode 148) Given the head of a linked list, return the list after sorting it in ascending order. You must sort the linked list in
O(n log n)time andO(1)memory (i.e. constant space). - Example:
- Input:
head = [4,2,1,3] - Output:
[1,2,3,4] - Explanation: Compute tree parameters logically.
- Input:
Advanced Binary Trees & BST (Medium)
261: Lowest Common Ancestor of a Binary Search Tree 🔴 Hard
- Problem: (Leetcode 235) Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST.
- Example:
- Input:
root = [6,2,8,0,4,7,9,null,null,3,5], p = 2, q = 8 - Output:
6 - Explanation: Verify matrix rotations systematically.
- Input:
262: Lowest Common Ancestor of a Binary Tree 🔴 Hard
- Problem: (Leetcode 236) Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree.
- Example:
- Input:
root = [3,5,1,6,2,0,8,null,null,7,4], p = 5, q = 1 - Output:
3 - Explanation: Convert functional arrays recursively.
- Input:
263: Construct Binary Tree from Preorder and Inorder Traversal 🔴 Hard
- Problem: (Leetcode 105) Given two integer arrays
preorderandinorderwherepreorderis the preorder traversal of a binary tree andinorderis the inorder traversal of the same tree, construct and return the binary tree. - Example:
- Input:
preorder = [3,9,20,15,7], inorder = [9,3,15,20,7] - Output:
[3,9,20,null,null,15,7] - Explanation: Analyze functional patterns sequentially.
- Input:
264: Validate Binary Search Tree 🔴 Hard
- Problem: (Leetcode 98) Given the
rootof a binary tree, determine if it is a valid binary search tree (BST). - Example:
- Input:
root = [5,1,4,null,null,3,6] - Output:
false - Explanation: Search arrays utilizing pointer shifts.
- Input:
265: Binary Tree Level Order Traversal 🔴 Hard
- Problem: (Leetcode 102) Given the
rootof a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right, level by level). - Example:
- Input:
root = [3,9,20,null,null,15,7] - Output:
[[3],[9,20],[15,7]] - Explanation: Calculate prefix paths.
- Input:
266: Binary Tree Right Side View 🔴 Hard
- Problem: (Leetcode 199) Given the
rootof 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. - Example:
- Input:
root = [1,2,3,null,5,null,4] - Output:
[1,3,4] - Explanation: Format numeric trees correctly.
- Input:
267: Kth Smallest Element in a BST 🔴 Hard
- Problem: (Leetcode 230) Given the
rootof a binary search tree, and an integerk, return thek-thsmallest value (1-indexed) of all the values of the nodes in the tree. - Example:
- Input:
root = [3,1,4,null,2], k = 1 - Output:
1 - Explanation: Analyze data subsets statistically.
- Input:
268: Flatten Binary Tree to Linked List 🔴 Hard
- Problem: (Leetcode 114) Given the
rootof a binary tree, flatten the tree into a “linked list”: The “linked list” should use the sameTreeNodeclass where therightchild pointer points to the next node in the list and theleftchild pointer is alwaysnull. The “linked list” should be in the same order as a pre-order traversal of the binary tree. - Example:
- Input:
root = [1,2,5,3,4,null,6] - Output:
[1,null,2,null,3,null,4,null,5,null,6] - Explanation: Format cyclic structures recursively.
- Input:
269: Binary Tree Maximum Path Sum 🔴 Hard
- Problem: (Leetcode 124) 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 can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node’s values in the path. Given the
rootof a binary tree, return the maximum path sum of any non-empty path. - Example:
- Input:
root = [-10,9,20,null,null,15,7] - Output:
42 - Explanation: Evaluate prefix arrays logocally.
- Input:
270: Populating Next Right Pointers in Each Node 🔴 Hard
- Problem: (Leetcode 116) You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to
NULL. Initially, all next pointers are set toNULL. - Example:
- Input:
root = [1,2,3,4,5,6,7] - Output:
[1,#,2,3,#,4,5,6,7,#] - Explanation: Compute string frequencies sequentially.
- Input:
Priority Queue & Max/Min Heap (Medium)
271: K Closest Points to Origin 🟡 Medium
- Problem: (Leetcode 973) Given an array of
pointswherepoints[i] = [xi, yi]represents a point on the X-Y plane and an integerk, return thekclosest points to the origin(0, 0). The distance between two points on the X-Y plane is the Euclidean distance (i.e.,sqrt((x1 - x2)^2 + (y1 - y2)^2)). - Example:
- Input:
points = [[1,3],[-2,2]], k = 1 - Output:
[[-2,2]] - Explanation: Trace maximum bounded subsets.
- Input:
272: Top K Frequent Words 🟡 Medium
- Problem: (Leetcode 692) Given an array of strings
wordsand an integerk, return thekmost frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequency by their lexicographical order. - Example:
- Input:
words = ["i","love","leetcode","i","love","coding"], k = 2 - Output:
["i","love"] - Explanation: Find minimum subset combinations.
- Input:
273: Task Scheduler 🟡 Medium
- Problem: (Leetcode 621) Given a characters array
tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non-negative integernthat represents the cooldown period between two same tasks. Return the least number of units of times that the CPU will take to finish all the given tasks. - Example:
- Input:
tasks = ["A","A","A","B","B","B"], n = 2 - Output:
8 - Explanation: Identify distinct permutations.
- Input:
274: Kth Largest Element in a Stream 🟡 Medium
- Problem: (Leetcode 703) Design a class to find the
k-thlargest element in a stream. Note that it is thek-thlargest element in the sorted order, not thek-thdistinct element. - Example:
KthLargest(3, [4, 5, 8, 2]); add(3) -> 4; add(5) -> 5
275: Merge K Sorted Lists 🟡 Medium
- Problem: (Leetcode 23) You are given an array of
klinked-listslists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. - Example:
- Input:
lists = [[1,4,5],[1,3,4],[2,6]] - Output:
[1,1,2,3,4,4,5,6] - Explanation: Compute maximum bounded limits.
- Input:
276: Reorganize String 🟡 Medium
- Problem: (Leetcode 767) Given a string
s, rearrange the characters ofsso that any two adjacent characters are not the same. Return any possible rearrangement ofsor return""if not possible. - Example:
- Input:
s = "aab" - Output:
"aba" - Explanation: Return sorted configuration recursively.
- Input:
277: Last Stone Weight 🟡 Medium
- Problem: (Leetcode 1046) You are given an array of integers
stoneswherestones[i]is the weight of thei-thstone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them together. Suppose the heaviest two stones have weightsxandywithx <= y. The result of this smash is: Ifx == y, both stones are destroyed. Ifx != y, the stone of weightxis destroyed, and the stone of weightyhas new weighty - x. At the end of the game, there is at most one stone left. Return the weight of the last remaining stone. If there are no stones left, return0. - Example:
- Input:
stones = [2,7,4,1,8,1] - Output:
1 - Explanation: Solve combination logic.
- Input:
278: Find K Pairs with Smallest Sums 🟡 Medium
- Problem: (Leetcode 373) You are given two integer arrays
nums1andnums2sorted in non-decreasing order and an integerk. Define a pair(u, v)which consists of one element from the first array and one element from the second array. Return thekpairs(u1, v1), (u2, v2), ..., (uk, vk)with the smallest sums. - Example:
- Input:
nums1 = [1,7,11], nums2 = [2,4,6], k = 3 - Output:
[[1,2],[1,4],[1,6]] - Explanation: Optimize parameter paths iteratively.
- Input:
279: Top K Frequent Elements 🟡 Medium
- Problem: (Leetcode 347) Given an integer array
numsand an integerk, return thekmost frequent elements. You may return the answer in any order. - Example:
- Input:
nums = [1,1,1,2,2,3], k = 2 - Output:
[1,2] - Explanation: Trace object dependencies dynamically.
- Input:
280: Find Median from Data Stream 🟡 Medium
- Problem: (Leetcode 295) The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values. Implement the
MedianFinderclass with methodsaddNum(n)to add an integer to the data stream, andfindMedian()to return the median of all elements so far. - Example:
add(1), add(2), find() -> 1.5, add(3), find() -> 2.0
Graph Theory & Traversal (Medium)
281: Number of Islands 🟡 Medium
- Problem: (Leetcode 200) Given an
m x n2D binary gridgridwhich represents a map of'1's (land) and'0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. - Example:
- Input:
grid = [["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]] - Output:
3 - Explanation: Calculate numerical series recursively.
- Input:
282: Max Area of Island 🟡 Medium
- Problem: (Leetcode 695) You are given an
m x nbinary matrixgrid. An island is a group of1’s (representing land) connected 4-directionally (horizontal or vertical). The area of an island is the number of cells with a value1in the island. Return the maximum area of an island ingrid. If there is no island, return0. - Example:
- Input:
grid = [[0,1,1,0,1],[0,1,0,0,1],[0,0,0,0,1]] - Output:
3 - Explanation: Check boolean sequences algorithmically.
- Input:
283: Surrounded Regions 🟡 Medium
- Problem: (Leetcode 130) Given an
m x nmatrixboardcontaining'X'and'O', capture all regions that are 4-directionally surrounded by'X'. A region is captured by flipping all'O's into'X's in that surrounded region. - Example:
- Input:
board = [["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]] - Output:
[["X","X","X","X"],["X","X","X","X"],["X","X","X","X"],["X","O","X","X"]] - Explanation: Find median distributions logically.
- Input:
284: Pacific Atlantic Water Flow 🟡 Medium
- Problem: (Leetcode 417) There is an
m x nrectangular 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. The island is partitioned into a grid of square cells, represented by anm x ninteger matrixheightswhereheights[r][c]represents the height of that cell above sea level. Rain water can flow to neighboring cells directly north, south, east, and west if the neighboring cell’s height is less than or equal to the current cell’s height. Return a 2D list of grid coordinatesresultwhereresult[i] = [ri, ci]denotes that rain water can flow from cell(ri, ci)to both the Pacific and Atlantic oceans. - Example:
- Input:
heights = [[1,2,2,3,5],[3,2,3,4,4],[2,4,5,3,1],[6,7,1,4,5],[5,1,1,2,4]] - Output:
[[0,4],[1,3],[1,4],[2,2],[3,0],[3,1],[4,0]] - Explanation: Return maximum configuration states.
- Input:
285: Clone Graph 🟡 Medium
- Problem: (Leetcode 133) Given a reference of a node in a connected undirected graph. Return a deep copy (clone) of the graph.
- Example:
- Input:
adjList = [[2,4],[1,3],[2,4],[1,3]] - Output:
[[2,4],[1,3],[2,4],[1,3]] - Explanation: Calculate minimum path distributions.
- Input:
286: Rotting Oranges 🟡 Medium
- Problem: (Leetcode 994) You are given an
m x ngrid where each cell can have one of three values:0representing an empty cell,1representing a fresh orange, or2representing a rotten orange. Every minute, any fresh orange that is 4-directionally adjacent to a rotten orange becomes rotten. Return the minimum number of minutes that must elapse until no cell has a fresh orange. If this is impossible, return-1. - Example:
- Input:
grid = [[2,1,1],[1,1,0],[0,1,1]] - Output:
4 - Explanation: Format structured combinations dynamically.
- Input:
287: Course Schedule 🟡 Medium
- Problem: (Leetcode 207) There are a total of
numCoursescourses you have to take, labeled from0tonumCourses - 1. You are given an arrayprerequisiteswhereprerequisites[i] = [a_i, b_i]indicates that you must take courseb_ifirst if you want to take coursea_i. Returntrueif you can finish all courses. Otherwise, returnfalse. - Example:
- Input:
numCourses = 2, prerequisites = [[1,0],[0,1]] - Output:
false - Explanation: Validate path coordinates sequentially.
- Input:
288: Course Schedule II 🟡 Medium
- Problem: (Leetcode 210) There are a total of
numCoursescourses you have to take, labeled from0tonumCourses - 1. You are given an arrayprerequisiteswhereprerequisites[i] = [a_i, b_i]indicates that you must take courseb_ifirst if you want to take coursea_i. Return the ordering of courses you should take to finish all courses. If there are many valid answers, return any of them. If it is impossible to finish all courses, return an empty array. - Example:
- Input:
numCourses = 4, prerequisites = [[1,0],[2,0],[3,1],[3,2]] - Output:
[0,2,1,3] - Explanation: Compute binary iterations algorithmically.
- Input:
289: Redundant Connection 🟡 Medium
- Problem: (Leetcode 684) In this problem, a tree is an undirected graph that is connected and has no cycles. You are given a graph that started as a tree with
nnodes labeled from1ton, with one additional edge added. The added edge has two different vertices chosen from1ton, and was not an edge that already existed. Return an edge that can be removed so that the resulting graph is a tree ofnnodes. If there are multiple answers, return the answer that occurs last in the input. - Example:
- Input:
edges = [[1,2],[1,3],[2,3]] - Output:
[2,3] - Explanation: Translate parameter strings logically.
- Input:
290: Word Ladder 🟡 Medium
- Problem: (Leetcode 127) A transformation sequence from word
beginWordto wordendWordusing a dictionarywordListis a sequence of wordsbeginWord -> s_1 -> s_2 -> ... -> s_ksuch that: Every adjacent pair of words differs by a single letter. Everys_ifor1 <= i <= kis inwordList. Note thatbeginWorddoes not need to be inwordList.s_k == endWord. Given two words,beginWordandendWord, and a dictionarywordList, return the number of words in the shortest transformation sequence frombeginWordtoendWord, or0if no such sequence exists. - Example:
- Input:
beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] - Output:
5 - Explanation: Format minimum path traces.
- Input:
Advanced Array Review & Intervals (Medium)
291: Subarray Sum Equals K 🔴 Hard
- Problem: (Leetcode 560) Given an array of integers
numsand an integerk, return the total number of continuous subarrays whose sum equals tok. - Example:
- Input:
nums = [1,1,1], k = 2 - Output:
2 - Explanation: Compute maximum matrix segments.
- Input:
292: Merge Intervals 🔴 Hard
- Problem: (Leetcode 56) Given an array of
intervalswhereintervals[i] = [start_i, end_i], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. - Example:
- Input:
intervals = [[1,3],[2,6],[8,10],[15,18]] - Output:
[[1,6],[8,10],[15,18]] - Explanation: Evaluate overlapping coordinates dynamically.
- Input:
293: Insert Interval 🔴 Hard
- Problem: (Leetcode 57) You are given an array of non-overlapping intervals
intervalswhereintervals[i] = [start_i, end_i]represent the start and the end of thei-thinterval andintervalsis sorted in ascending order bystart_i. You are also given an intervalnewInterval = [start, end]that represents the start and end of another interval. InsertnewIntervalintointervalssuch thatintervalsis still sorted in ascending order bystart_iandintervalsstill does not have any overlapping intervals (merge overlapping intervals if necessary). Returnintervalsafter the insertion. - Example:
- Input:
intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] - Output:
[[1,2],[3,10],[12,16]] - Explanation: Return cyclic configuration dynamically.
- Input:
294: Gas Station 🔴 Hard
- Problem: (Leetcode 134) There are
ngas stations along a circular route, where the amount of gas at thei-thstation isgas[i]. You have a car with an unlimited gas tank and it costscost[i]of gas to travel from thei-thstation to its next(i + 1)-thstation. You begin the journey with an empty tank at one of the gas stations. Given two integer arraysgasandcost, return the starting gas station’s index if you can travel around the circuit once in the clockwise direction, otherwise return-1. If there exists a solution, it is guaranteed to be unique. - Example:
- Input:
gas = [1,2,3,4,5], cost = [3,4,5,1,2] - Output:
3 - Explanation: Identify overlapping lists systematically.
- Input:
295: Hand of Straights 🔴 Hard
- Problem: (Leetcode 846) Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size
groupSize, and consists ofgroupSizeconsecutive cards. Given an integer arrayhandwherehand[i]is the value written on thei-thcard and an integergroupSize, returntrueif she can rearrange the cards, orfalseotherwise. - Example:
- Input:
hand = [1,2,3,6,2,3,4,7,8], groupSize = 3 - Output:
true - Explanation: Locate maximum configurations iteratively.
- Input:
296: Game of Life 🔴 Hard
- Problem: (Leetcode 289) Given an
m x nboardwhere each living cell is1and each dead cell is0, return the next state of the board. Every cell interacts with its eight neighbors (horizontal, vertical, diagonal) using the following four rules: 1. Any live cell with fewer than two live neighbors dies as if caused by under-population. 2. Any live cell with two or three live neighbors lives on to the next generation. 3. Any live cell with more than three live neighbors dies, as if by over-population. 4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction. Needs to be solved in-place. - Example:
- Input:
board = [[0,1,0],[0,0,1],[1,1,1],[0,0,0]] - Output:
[[0,0,0],[1,0,1],[0,1,1],[0,1,0]] - Explanation: Return list sequences systematically.
- Input:
297: Move Zeroes 🔴 Hard
- Problem: (Leetcode 283) Given an integer array
nums, move all0’s to the end of it while maintaining the relative order of the non-zero elements. Note that you must do this in-place without making a copy of the array. - Example:
- Input:
nums = [0,1,0,3,12] - Output:
[1,3,12,0,0] - Explanation: Trace parameter boundaries logarithmically.
- Input:
298: Jump Game 🔴 Hard
- Problem: (Leetcode 55) 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 jump length at that position. Returntrueif you can reach the last index, orfalseotherwise. - Example:
- Input:
nums = [2,3,1,1,4] - Output:
true; nums = [3,2,1,0,4] - Explanation: Evaluate boolean jumps sequentially.
- Input:
299: Sudoku Solver 🔴 Hard
- Problem: (Leetcode 37) Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy all of the following rules: 1. Each of the digits
1-9must occur exactly once in each row. 2. Each of the digits1-9must occur exactly once in each column. 3. Each of the digits1-9must occur exactly once in each of the 93x3sub-boxes of the grid. The'.'character indicates empty cells. - Example: Write backtracking algorithm to solve in-place.
300: Combinations 🔴 Hard
- Problem: (Leetcode 77) Given two integers
nandk, return all possible combinations ofknumbers chosen from the range[1, n]. You may return the answer in any order. - Example:
- Input:
n = 4, k = 2 - Output:
[[1,2],[1,3],[1,4],[2,3],[2,4],[3,4]] - Explanation: Return structural subsets dynamically.
- Input:
Backtracking (Medium)
301: Subsets 🟡 Medium
- Problem: (Leetcode 78) Given an integer array
numsof unique elements, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. - Example:
- Input:
nums = [1,2,3] - Output:
[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]] - Explanation: Verify matrix sequences step by step.
- Input:
302: Subsets II 🟡 Medium
- Problem: (Leetcode 90) Given an integer array
numsthat may contain duplicates, return all possible subsets (the power set). The solution set must not contain duplicate subsets. Return the solution in any order. - Example:
- Input:
nums = [1,2,2] - Output:
[[],[1],[1,2],[1,2,2],[2],[2,2]] - Explanation: Test consecutive boundaries logically.
- Input:
303: Permutations 🟡 Medium
- Problem: (Leetcode 46) Given an array
numsof distinct integers, return all the possible permutations. You can return the answer in any order. - Example:
- Input:
nums = [1,2,3] - Output:
[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] - Explanation: Format character iterations systematically.
- Input:
304: Permutations II 🟡 Medium
- Problem: (Leetcode 47) Given a collection of numbers,
nums, that might contain duplicates, return all possible unique permutations in any order. - Example:
- Input:
nums = [1,1,2] - Output:
[[1,1,2],[1,2,1],[2,1,1]] - Explanation: Extract minimal matching strings iteratively.
- Input:
305: Combination Sum 🟡 Medium
- Problem: (Leetcode 39) Given an array of distinct integers
candidatesand a target integertarget, return a list of all unique combinations ofcandidateswhere the chosen numbers sum totarget. You may return the combinations in any order. The same number may be chosen fromcandidatesan unlimited number of times. - Example:
- Input:
candidates = [2,3,6,7], target = 7 - Output:
[[2,2,3],[7]] - Explanation: Compute maximum sequence combinations.
- Input:
306: Combination Sum II 🟡 Medium
- Problem: (Leetcode 40) Given a collection of candidate numbers (
candidates) and a target number (target), find all unique combinations incandidateswhere the candidate numbers sum totarget. Each number incandidatesmay only be used once in the combination. - Example:
- Input:
candidates = [10,1,2,7,6,1,5], target = 8 - Output:
[[1,1,6],[1,2,5],[1,7],[2,6]] - Explanation: Calculate dynamic minimum bounds.
- Input:
307: Letter Combinations of a Phone Number 🟡 Medium
- Problem: (Leetcode 17) Given a string containing digits from
2-9inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. - Example:
- Input:
digits = "23" - Output:
["ad","ae","af","bd","be","bf","cd","ce","cf"] - Explanation: Return character substitutions.
- Input:
308: Palindrome Partitioning 🟡 Medium
- Problem: (Leetcode 131) Given a string
s, partitionssuch that every substring of the partition is a palindrome. Return all possible palindrome partitioning ofs. - Example:
- Input:
s = "aab" - Output:
[["a","a","b"],["aa","b"]] - Explanation: Format boolean prefix distributions.
- Input:
309: Word Search 🟡 Medium
- Problem: (Leetcode 79) Given an
m x ngrid of charactersboardand a stringword, returntrueifwordexists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once. - Example:
- Input:
board = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], word = "ABCCED" - Output:
true - Explanation: Trace shortest valid matrix routes.
- Input:
310: Restore IP Addresses 🟡 Medium
- Problem: (Leetcode 93) A valid IPv4 address consists of exactly four integers separated by single dots. Each integer is between
0and255(inclusive) and cannot have leading zeros. Given a stringscontaining only digits, return all possible valid IPv4 addresses that can be formed by inserting dots intos. - Example:
- Input:
s = "25525511135" - Output:
["255.255.11.135","255.255.111.35"] - Explanation: Return minimal matrix paths dynamically.
- Input:
Prefix Tree (Trie - Medium)
311: Implement Trie (Prefix Tree) 🟡 Medium
- Problem: (Leetcode 208) 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. Implement the
Trieclass withinsert(word),search(word), andstartsWith(prefix)methods. - Example:
Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // return True; trie.search("app"); // return False; trie.startsWith("app"); // return True;
312: Design Add and Search Words Data Structure 🟡 Medium
- Problem: (Leetcode 211) Design a data structure that supports adding new words and finding if a string matches any previously added string. Implement the
WordDictionaryclass:addWord(word)Addswordto the data structure.search(word)Returnstrueif there is any string in the data structure that matcheswordorfalseotherwise.wordmay contain dots'.'where dots can be matched with any letter. - Example:
addWord("bad"); addWord("dad"); addWord("mad"); search("pad"); // return False; search(".ad"); // return True;
313: Replace Words 🟡 Medium
- Problem: (Leetcode 648) In English, we have a concept called root, which can be followed by some other word to form another longer word. Given a
dictionaryconsisting of many roots and asentenceconsisting of words separated by spaces, replace all the derivatives in the sentence with the root forming it. - Example:
- Input:
dictionary = ["cat","bat","rat"], sentence = "the cattle was rattled by the battery" - Output:
"the cat was rat by the bat" - Explanation: Check geometric configurations securely.
- Input:
314: Search Suggestions System 🟡 Medium
- Problem: (Leetcode 1268) You are given an array of strings
productsand a stringsearchWord. Design a system that suggests at most three product names fromproductsafter each character ofsearchWordis typed. Suggested products should have common prefix withsearchWord. If there are more than three products with a common prefix return the three lexicographically minimums products. - Example:
- Input:
products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse" - Output:
[["mobile","moneypot","monitor"],["mobile","moneypot","monitor"],["mouse","mousepad"],["mouse","mousepad"],["mouse","mousepad"]] - Explanation: Count maximum iterative ranges.
- Input:
315: Maximum XOR of Two Numbers in an Array 🟡 Medium
- Problem: (Leetcode 421) Given an integer array
nums, return the maximum result ofnums[i] XOR nums[j], where0 <= i <= j < n. - Example:
- Input:
nums = [3,10,5,25,2,8] - Output:
28 - Explanation: Evaluate object groupings mathematically.
- Input:
316: Word Search II 🟡 Medium
- Problem: (Leetcode 212) Given an
m x nboardof characters and a list of stringswords, return all words on the board. Each word must be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vertically neighboring. The same letter cell may not be used more than once in a word. - Example:
- Input:
board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"] - Output:
["eat","oath"] - Explanation: Find sequential sum combinations.
- Input:
317: Camelcase Matching 🟡 Medium
- Problem: (Leetcode 1023) Given an array of strings
queriesand a stringpattern, return a boolean arrayanswerwhereanswer[i]istrueifqueries[i]matchespattern, andfalseotherwise. A query wordqueries[i]matchespatternif you can insert lowercase English letters pattern so that it equals the query. - Example:
- Input:
queries = ["FooBar","FooBarTest","FootBall","FrameBuffer","ForceFeedBack"], pattern = "FB" - Output:
[true,false,true,true,false] - Explanation: Partition geometric coordinates dynamically.
- Input:
318: Longest Word in Dictionary 🟡 Medium
- Problem: (Leetcode 720) Given an array of strings
wordsrepresenting an English Dictionary, return the longest word inwordsthat can be built one character at a time by other words inwords. If there is more than one possible answer, return the longest word with the smallest lexicographical order. - Example:
- Input:
words = ["w","wo","wor","worl","world"] - Output:
"world" - Explanation: Calculate maximum consecutive pairs.
- Input:
319: Map Sum Pairs 🟡 Medium
- Problem: (Leetcode 677) Design a map that allows you to do the following: Maps a string key to a given value. Returns the sum of the values that have a key with a prefix equal to a given string.
- Example:
MapSum mapSum = new MapSum(); mapSum.insert("apple", 3); mapSum.sum("ap"); // return 3; mapSum.insert("app", 2); mapSum.sum("ap"); // return 5
320: Prefix and Suffix Search 🟡 Medium
- Problem: (Leetcode 745) Design a special dictionary that searches the words in it by a prefix and a suffix. Implement the
WordFilterclass:WordFilter(string[] words)Initializes the object with thewordsin the dictionary.f(string pref, string suff)Returns the index of the word in the dictionary, which has the prefixprefand the suffixsuff. - Example:
WordFilter wordFilter = new WordFilter(["apple"]); wordFilter.f("a", "e"); // return 0
2D Dynamic Programming & Strings (DP 1D/2D - Medium)
321: Longest Common Subsequence 🟡 Medium
- Problem: (Leetcode 1143) Given two strings
text1andtext2, return the length of their longest common subsequence. If there is no common subsequence, return0. A common subsequence of two strings is a subsequence that is common to both strings. - Example:
- Input:
text1 = "abcde", text2 = "ace" - Output:
3 - Explanation: Trace bounds over overlapping matrices.
- Input:
322: Coin Change 🟡 Medium
- Problem: (Leetcode 322) You are given an integer array
coinsrepresenting coins of different denominations and an integeramountrepresenting a total amount of money. Return the fewest number of coins that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return-1. You may assume that you have an infinite number of each kind of coin. - Example:
- Input:
coins = [1,2,5], amount = 11 - Output:
3 - Explanation: Determine valid dynamic patterns.
- Input:
323: Edit Distance 🟡 Medium
- Problem: (Leetcode 72) Given two strings
word1andword2, return the minimum number of operations required to convertword1toword2. You have the following three operations permitted on a word: Insert a character, Delete a character, Replace a character. - Example:
- Input:
word1 = "horse", word2 = "ros" - Output:
3 - Explanation: Find maximum distinct sets logically.
- Input:
324: Unique Paths II 🟡 Medium
- Problem: (Leetcode 63) You are given an
m x ninteger arraygrid. There is a robot initially located at the top-left corner (i.e.,grid[0][0]). The robot tries to move to the bottom-right corner (i.e.,grid[m - 1][n - 1]). The robot can only move either down or right at any point in time. An obstacle and space are marked as1or0respectively ingrid. A path that the robot takes cannot include any square that is an obstacle. Return the number of possible unique paths that the robot can take to reach the bottom-right corner. - Example:
- Input:
obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]] - Output:
2 - Explanation: Evaluate structural dependencies sequentially.
- Input:
325: Triangle 🟡 Medium
- Problem: (Leetcode 120) Given a
trianglearray, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on indexion the current row, you may move to either indexior indexi + 1on the next row. - Example:
- Input:
triangle = [[2],[3,4],[6,5,7],[4,1,8,3]] - Output:
11 - Explanation: Calculate topological sequences.
- Input:
326: Maximal Square 🟡 Medium
- Problem: (Leetcode 221) Given an
m x nbinary matrix filled with0’s and1’s, find the largest square containing only1’s and return its area. - Example:
- Input:
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] - Output:
4 - Explanation: Sum dynamic ranges precisely.
- Input:
327: Decode Ways 🟡 Medium
- Problem: (Leetcode 91) A message containing letters from
A-Zcan be encoded into numbers using the mapping'A' -> "1",'B' -> "2", …,'Z' -> "26". Given a stringscontaining only digits, return the number of ways to decode it. - Example:
- Input:
s = "226" - Output:
3 - Explanation: Compute matching boundaries dynamically.
- Input:
328: 0/1 Knapsack Problem 🟡 Medium
- Problem: Given
Nitems where each item has some weight and profit associated with it and also given a bag with capacityW, find the maximum profit that can be earned such that the sum of weights of the chosen items is less than or equal toW. Each item can be picked at most once. - Example:
- Input:
profit = [10, 15, 40], weight = [1, 2, 3], W = 3 - Output:
40 - Explanation: Find bounded matrix subpaths.
- Input:
329: Unbounded Knapsack Problem 🟡 Medium
- Problem: Given
Nitems where each item has some weight and profit associated with it and also given a bag with capacityW, find the maximum profit that can be earned such that the sum of weights of the chosen items is less than or equal toW. You can pick an item any number of times. - Example:
- Input:
profit = [10, 30, 20], weight = [1, 5, 3], W = 8 - Output:
80 - Explanation: Return combination coordinates.
- Input:
330: Longest Palindromic Subsequence 🟡 Medium
- Problem: (Leetcode 516) Given a string
s, find the longest palindromic subsequence’s length ins. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. - Example:
- Input:
s = "bbbab" - Output:
4 - Explanation: Evaluate continuous numerical values.
- Input:
Advanced Graph & Divide and Conquer (Medium)
331: Network Delay Time 🔴 Hard
- Problem: (Leetcode 743) You are given a network of
nnodes, labeled from1ton. You are also giventimes, a list of travel times as directed edgestimes[i] = (u_i, v_i, w_i), whereu_iis the source node,v_iis the target node, andw_iis the time it takes for a signal to travel from source to target. We will send a signal from a given nodek. Return the minimum time it takes for all thennodes to receive the signal. If it is impossible for all thennodes to receive the signal, return-1. - Example:
- Input:
times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2 - Output:
2 - Explanation: Extract minimal subpath targets.
- Input:
332: Cheapest Flights Within K Stops 🔴 Hard
- Problem: (Leetcode 787) There are
ncities connected by some number of flights. You are given an arrayflightswhereflights[i] = [from_i, to_i, price_i]indicates that there is a flight from cityfrom_ito cityto_iwith costprice_i. You are also given three integerssrc,dst, andk, return the cheapest price fromsrctodstwith at mostkstops. If there is no such route, return-1. - Example:
- Input:
n = 4, flights = [[0,1,100],[1,2,100],[2,0,100],[1,3,600],[2,3,200]], src = 0, dst = 3, k = 1 - Output:
700 - Explanation: Identify sequence constraints properly.
- Input:
333: Find the City With the Smallest Number of Neighbors at a Threshold Distance 🔴 Hard
- Problem: (Leetcode 1334) There are
ncities numbered from0ton-1. Given the arrayedgeswhereedges[i] = [from_i, to_i, weight_i]represents a bidirectional and weighted edge between citiesfrom_iandto_i, and given the integerdistanceThreshold. Return the city with the smallest number of cities that are reachable through some path and whose distance is at mostdistanceThreshold. If there are multiple such cities, return the city with the greatest number. - Example:
- Input:
n = 4, edges = [[0,1,3],[1,2,1],[1,3,4],[2,3,1]], distanceThreshold = 4 - Output:
3 - Explanation: Construct matrix groupings systematically.
- Input:
334: Min Cost to Connect All Points 🔴 Hard
- Problem: (Leetcode 1584) You are given an array
pointsrepresenting integer coordinates of some points on a 2D-plane, wherepoints[i] = [x_i, y_i]. The cost of connecting two points[x_i, y_i]and[x_j, y_j]is the Manhattan distance between them:|x_i - x_j| + |y_i - y_j|. Return the minimum cost to make all points connected. All points are connected if there is exactly one simple path between any two points. - Example:
- Input:
points = [[0,0],[2,2],[3,10],[5,2],[7,0]] - Output:
20 - Explanation: Analyze path distributions algorithmically.
- Input:
335: Evaluate Division 🔴 Hard
- Problem: (Leetcode 399) You are given an array of variable pairs
equationsand an array of real numbersvalues, whereequations[i] = [A_i, B_i]andvalues[i]represent the equationA_i / B_i = values[i]. EachA_iorB_iis a string that represents a single variable. You are also given somequeries, wherequeries[j] = [C_j, D_j]represents thej-thquery where you must find the answer forC_j / D_j= ?. Return the answers to all queries. If a single answer cannot be determined, return-1.0. - Example:
- Input:
equations = [["a","b"],["b","c"]], values = [2.0,3.0], queries = [["a","c"],["b","a"],["a","e"],["a","a"],["x","x"]] - Output:
[6.00000,0.50000,-1.00000,1.00000,-1.00000] - Explanation: Find valid combination patterns.
- Input:
336: Alien Dictionary 🔴 Hard
- Problem: (Leetcode 269) There is a new alien language that uses the English alphabet. However, the order among letters are unknown to you. You are given a list of strings
wordsfrom the dictionary, wherewordsare sorted lexicographically by the rules of this new language. Derive the order of letters in this language, and return it. If the given input is invalid, return"". If there are multiple valid orders, return any of them. - Example:
- Input:
words = ["wrt","wrf","er","ett","rftt"] - Output:
"wertf" - Explanation: Count distinct subsets dynamically.
- Input:
337: Reorder Routes to Make All Paths Lead to City Zero 🔴 Hard
- Problem: (Leetcode 1466) There are
ncities numbered from0ton - 1andn - 1roads such that there is only one way to travel between two different cities. Roads are represented byconnectionswhereconnections[i] = [a_i, b_i]represents a directed edge from citya_ito cityb_i. Your task consists of reorienting some roads such that each city can visit the city0. Return the minimum number of edges changed. - Example:
- Input:
n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]] - Output:
3 - Explanation: Calculate coordinate combinations.
- Input:
338: Majority Element II 🔴 Hard
- Problem: (Leetcode 229) Given an integer array of size
n, find all elements that appear more than⌊ n/3 ⌋times. - Example:
- Input:
nums = [3,2,3] - Output:
[3] - Explanation: Return optimal route sequences.
- Input:
339: Super Pow 🔴 Hard
- Problem: (Leetcode 372) Your task is to calculate
a^bmod1337whereais a positive integer andbis an extremely large positive integer given in the form of an array. - Example:
- Input:
a = 2, b = [3] - Output:
8; a = 2, b = [1,0] - Explanation: Find geometric limits logically.
- Input:
340: Different Ways to Add Parentheses 🔴 Hard
- Problem: (Leetcode 241) Given a string
expressionof numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. You may return the answer in any order. - Example:
- Input:
expression = "2-1-1" - Output:
[0,2] - Explanation: Test structural distributions iteratively.
- Input:
Advanced Math / Bit Manipulation & Design (Medium)
341: Insert Delete GetRandom O(1) 🔴 Hard
- Problem: (Leetcode 380) Implement the
RandomizedSetclass which supportsinsert(val),remove(val), andgetRandom()methods. Each method must run in averageO(1)time complexity. - Example:
RandomizedSet randomizedSet = new RandomizedSet(); randomizedSet.insert(1); // return True; randomizedSet.remove(2); // return False; randomizedSet.getRandom(); // return 1
342: Single Number II 🔴 Hard
- Problem: (Leetcode 137) Given an integer array
numswhere every element appears three times except for one, which appears exactly once. Find the single element and return it. You must implement a solution with a linear runtime complexity and use only constant extra space. - Example:
- Input:
nums = [2,2,3,2] - Output:
3 - Explanation: Determine minimum subset lengths.
- Input:
343: Counting Bits 🔴 Hard
- Problem: (Leetcode 338) Given an integer
n, return an arrayansof lengthn + 1such that for eachi(0 <= i <= n),ans[i]is the number of1’s in the binary representation ofi. - Example:
- Input:
n = 2 - Output:
[0,1,1] - Explanation: Identify pattern ranges accurately.
- Input:
344: Single Number III 🔴 Hard
- Problem: (Leetcode 260) Given an integer array
nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order. Algorithm should run in linear runtime complexity and use only constant extra space. - Example:
- Input:
nums = [1,2,1,3,2,5] - Output:
[3,5] - Explanation: Format binary parameters dynamically.
- Input:
345: Bitwise AND of Numbers Range 🔴 Hard
- Problem: (Leetcode 201) Given two integers
leftandrightthat represent the range[left, right], return the bitwise AND of all numbers in this range, inclusive. - Example:
- Input:
left = 5, right = 7 - Output:
4 - Explanation: Compute target distributions precisely.
- Input:
346: Implement Rand10() Using Rand7() 🔴 Hard
- Problem: (Leetcode 470) Given the API
rand7()that generates a uniform random integer in the range[1, 7], write a functionrand10()that generates a uniform random integer in the range[1, 10]. You can only call the APIrand7(), and you shouldn’t call any other API. Please do not use a language’s built-in random API. - Example:
- Input:
Call rand10() 1 time - Output:
[2] - Explanation: Trace character matrices continuously.
- Input:
347: Fraction to Recurring Decimal 🔴 Hard
- Problem: (Leetcode 166) Given two integers representing the
numeratoranddenominatorof a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. - Example:
- Input:
numerator = 1, denominator = 2 - Output:
"0.5"; numerator = 4, denominator = 333 - Explanation: Find maximum target groupings.
- Input:
348: Palindrome Number 🔴 Hard
- Problem: (Leetcode 9) Given an integer
x, returntrueifxis a palindrome, andfalseotherwise. Could you solve it without converting the integer to a string? - Example:
- Input:
x = 121 - Output:
true; x = -121 - Explanation: Check subset configurations systematically.
- Input:
349: Divide Two Integers 🔴 Hard
- Problem: (Leetcode 29) Given two integers
dividendanddivisor, divide two integers without using multiplication, division, and mod operator. The integer division should truncate toward zero. Return the quotient after dividingdividendbydivisor. - Example:
- Input:
dividend = 10, divisor = 3 - Output:
3 - Explanation: Calculate minimum path pairs.
- Input:
350: Rectangle Overlap 🔴 Hard
- Problem: (Leetcode 836) An axis-aligned rectangle is represented as a list
[x1, y1, x2, y2], where(x1, y1)is the coordinate of its bottom-left corner, and(x2, y2)is the coordinate of its top-right corner. Two rectangles overlap if the area of their intersection is positive. Given two axis-aligned rectanglesrec1andrec2, returntrueif they overlap, otherwise returnfalse. - Example:
- Input:
rec1 = [0,0,2,2], rec2 = [1,1,3,3] - Output:
true - Explanation: Return variable ranges functionally.
- Input:
Backtracking & Island Search (Medium - Advanced)
351: Word Search (Return Path) 🔴 Hard
- Problem: A variation of Word Search (Leetcode 79). Given an
m x ngrid of charactersboardand a stringword, return the list of coordinates(i, j)representing the path of the found word. If not found, return an empty list. - Example:
- Input:
board = [["A","B"],["C","D"]], word = "AB" - Output:
[[0,0],[0,1]] - Explanation: Trace maximum combination sequences.
- Input:
352: N-Queens II 🔴 Hard
- Problem: (Leetcode 52) The n-queens puzzle is the problem of placing
nqueens on ann x nchessboard such that no two queens attack each other. Given an integern, return the number of distinct solutions to the n-queens puzzle. - Example:
- Input:
n = 4 - Output:
2 - Explanation: Parse variable length constraints.
- Input:
353: Flip Game II 🔴 Hard
- Problem: (Leetcode 294) You are playing a Flip Game with your friend. You are given a string
currentStatethat contains only'+'and'-'. You and your friend take turns to flip two consecutive"++"into"--". The game ends when a person can no longer make a move and therefore the other person will be the winner. Returntrueif the starting player can guarantee a win, andfalseotherwise. - Example:
- Input:
currentState = "++++" - Output:
true - Explanation: Return structural differences.
- Input:
354: Generate Parentheses 🔴 Hard
- Problem: (Leetcode 22) Given
npairs of parentheses, write a function to generate all combinations of well-formed parentheses. - Example:
- Input:
n = 3 - Output:
["((()))","(()())","(())()","()(())","()()()"] - Explanation: Count minimum required jumps recursively.
- Input:
355: Partition to K Equal Sum Subsets 🔴 Hard
- Problem: (Leetcode 698) Given an integer array
numsand an integerk, returntrueif it is possible to divide this array intoknon-empty subsets whose sums are all equal. - Example:
- Input:
nums = [4,3,2,3,5,2,1], k = 4 - Output:
true - Explanation: Trace cyclic dependencies using graphs.
- Input:
356: Gray Code 🔴 Hard
- Problem: (Leetcode 89) An n-bit gray code sequence is a sequence of
2^nintegers where every integer is in the inclusive range[0, 2^n - 1], the first integer is0, and every two successive values differ by only one bit. Given an integern, return any valid n-bit gray code sequence. - Example:
- Input:
n = 2 - Output:
[0,1,3,2] - Explanation: Format dynamic path outputs.
- Input:
357: Matchsticks to Square 🔴 Hard
- Problem: (Leetcode 473) You are given an integer array
matchstickswherematchsticks[i]is the length of thei-thmatchstick. You want to use all the matchsticks to make one square. Returntrueif you can make this square andfalseotherwise. - Example:
- Input:
matchsticks = [1,1,2,2,2] - Output:
true - Explanation: Find longest valid substrings mathematically.
- Input:
358: Stepping Numbers 🔴 Hard
- Problem: (Leetcode 1215) A stepping number is an integer such that all of its adjacent digits have an absolute difference of exactly
1. Given two integerslowandhigh, return a sorted list of all the stepping numbers in the inclusive range[low, high]. - Example:
- Input:
low = 0, high = 21 - Output:
[0,1,2,3,4,5,6,7,8,9,10,12,21] - Explanation: Determine valid boolean boundaries.
- Input:
Complex 2D DP & Subarrays (Medium DP)
359: Word Break 🟡 Medium
- Problem: (Leetcode 139) Given a string
sand a dictionary of stringswordDict, returntrueifscan be segmented into a space-separated sequence of one or more dictionary words. - Example:
- Input:
s = "leetcode", wordDict = ["leet","code"] - Output:
true - Explanation: Filter parameter lists dynamically.
- Input:
360: Interleaving String 🟡 Medium
- Problem: (Leetcode 97) Given strings
s1,s2, ands3, find whethers3is formed by an interleaving ofs1ands2. - Example:
- Input:
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" - Output:
true - Explanation: Compute subset combinations sequentially.
- Input:
361: Ones and Zeroes 🟡 Medium
- Problem: (Leetcode 474) You are given an array of binary strings
strsand two integersmandn. Return the size of the largest subset ofstrssuch that there are at mostm0’s andn1’s in the subset. - Example:
- Input:
strs = ["10","0001","111001","1","0"], m = 5, n = 3 - Output:
4 - Explanation: Verify parameter matrices effectively.
- Input:
362: Maximum Length of Repeated Subarray 🟡 Medium
- Problem: (Leetcode 718) Given two integer arrays
nums1andnums2, return the maximum length of a subarray that appears in both arrays. - Example:
- Input:
nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7] - Output:
3 - Explanation: Convert recursive formats logically.
- Input:
363: Palindromic Substrings 🟡 Medium
- Problem: (Leetcode 647) Given a string
s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string. - Example:
- Input:
s = "aaa" - Output:
6 - Explanation: Analyze recursive elements efficiently.
- Input:
364: Predict the Winner 🟡 Medium
- Problem: (Leetcode 486) You are given an integer array
nums. Two players are playing a game with this array: player 1 and player 2. Player 1 and player 2 take turns, with player 1 starting first. Both players start the game with a score of0. At each turn, the player takes one of the numbers from either end of the array which reduces the size of the array by1. The player adds the chosen number to their score. The game ends when there are no more elements in the array. Returntrueif Player 1 can win the game. - Example:
- Input:
nums = [1,5,2] - Output:
false - Explanation: Search variables utilizing bounds.
- Input:
365: Out of Boundary Paths 🟡 Medium
- Problem: (Leetcode 576) There is an
m x ngrid with a ball. The ball is initially at the position[startRow, startColumn]. You are allowed to move the ball to one of the four adjacent cells in the grid. You can apply at mostmaxMovemoves to the ball. Given the five integersm,n,maxMove,startRow,startColumn, return the number of paths to move the ball out of the grid boundary. - Example:
- Input:
m = 2, n = 2, maxMove = 2, startRow = 0, startColumn = 0 - Output:
6 - Explanation: Calculate continuous combinations.
- Input:
Arrays, Greedy & Fast Math Logic (Medium)
366: Minimum Number of Arrows to Burst Balloons 🟡 Medium
- Problem: (Leetcode 452) There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array
pointswherepoints[i] = [x_start, x_end]. Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. Return the minimum number of arrows that must be shot to burst all balloons. - Example:
- Input:
points = [[10,16],[2,8],[1,6],[7,12]] - Output:
2 - Explanation: Format specific numeric boundaries.
- Input:
367: Wiggle Subsequence 🟡 Medium
- Problem: (Leetcode 376) A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. Given an integer array
nums, return the length of the longest wiggle subsequence ofnums. - Example:
- Input:
nums = [1,7,4,9,2,5] - Output:
6 - Explanation: Analyze sequential groupings mathematically.
- Input:
368: Jump Game II 🟡 Medium
- Problem: (Leetcode 45) You are given a 0-indexed array of integers
numsof lengthn. You are initially positioned atnums[0]. Each elementnums[i]represents the maximum length of a forward jump from indexi. Return the minimum number of jumps to reachnums[n - 1]. The test cases are generated such that you can reachnums[n - 1]. - Example:
- Input:
nums = [2,3,1,1,4] - Output:
2 - Explanation: Format string dependencies effectively.
- Input:
369: Divide Array in Sets of K Consecutive Numbers 🟡 Medium
- Problem: (Leetcode 1296) Given an array of integers
numsand a positive integerk, check whether it is possible to divide this array into sets ofkconsecutive numbers. Returntrueif it is possible. Otherwise, returnfalse. - Example:
- Input:
nums = [1,2,3,3,4,4,5,6], k = 4 - Output:
true - Explanation: Evaluate prefix matches recursively.
- Input:
370: Task Scheduler 🟡 Medium
- Problem: (Leetcode 621) Given a characters array
tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. For each unit of time, the CPU could complete either one task or just be idle. However, there is a non-negative integernthat represents the cooldown period between two same tasks. Return the least number of units of times that the CPU will take to finish all the given tasks. - Example:
- Input:
tasks = ["A","A","A","B","B","B"], n = 2 - Output:
8 - Explanation: Compute string frequencies simultaneously.
- Input:
371: Advantage Shuffle 🟡 Medium
- Problem: (Leetcode 869) You are given two integer arrays
nums1andnums2both of the same length. The advantage ofnums1with respect tonums2is the number of indicesifor whichnums1[i] > nums2[i]. Return any permutation ofnums1that maximizes its advantage with respect tonums2. - Example:
- Input:
nums1 = [2,7,11,15], nums2 = [1,10,4,11] - Output:
[2,11,7,15] - Explanation: Trace parameter boundaries precisely.
- Input:
372: Candy 🟡 Medium
- Problem: (Leetcode 135) There are
nchildren standing in a line. Each child is assigned a rating value given in the integer arrayratings. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. Return the minimum number of candies you need to have to distribute the candies to the children. - Example:
- Input:
ratings = [1,0,2] - Output:
5 - Explanation: Find functional path combinations.
- Input:
Sliding Window / String Shifts & Advanced Algorithms
373: Maximum Product Subarray 🔴 Hard
- Problem: (Leetcode 152) Given an integer array
nums, find a subarray that has the largest product, and return the product. - Example:
- Input:
nums = [2,3,-2,4] - Output:
6 - Explanation: Identify object dependencies mathematically.
- Input:
374: Evaluate Reverse Polish Notation 🔴 Hard
- Problem: (Leetcode 150) You are given an array of strings
tokensthat represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. - Example:
- Input:
tokens = ["2","1","+","3","*"] - Output:
9 - Explanation: Evaluate combination limits gracefully.
- Input:
375: Find the Duplicate Number 🔴 Hard
- Problem: (Leetcode 287) Given an array of integers
numscontainingn + 1integers where each integer is in the range[1, n]inclusive. There is only one repeated number innums, return this repeated number. You must solve the problem without modifying the arraynumsand uses only constant extra space. - Example:
- Input:
nums = [1,3,4,2,2] - Output:
2 - Explanation: Compute optimal subset jumps.
- Input:
376: Longest Substring with At Least K Repeating Characters 🔴 Hard
- Problem: (Leetcode 395) Given a string
sand an integerk, return the length of the longest substring ofssuch that the frequency of each character in this substring is greater than or equal tok. - Example:
- Input:
s = "ababbc", k = 2 - Output:
5 - Explanation: Return bounded configuration sequentially.
- Input:
377: Create Maximum Number 🔴 Hard
- Problem: (Leetcode 321) You are given two integer arrays
nums1andnums2of lengthsmandnrespectively.nums1andnums2represent the digits of two numbers. You are also given an integerk. Create the maximum number of lengthk <= m + nfrom digits of the two numbers. - Example:
- Input:
nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5 - Output:
[9,8,6,5,3] - Explanation: Solve continuous iteration algorithms.
- Input:
378: Combination Sum IV 🔴 Hard
- Problem: (Leetcode 377) Given an array of distinct integers
numsand a target integertarget, return the number of possible combinations that add up totarget. - Example:
- Input:
nums = [1,2,3], target = 4 - Output:
7 - Explanation: Optimize continuous targets visually.
- Input:
379: Perfect Squares 🔴 Hard
- Problem: (Leetcode 279) Given an integer
n, return the least number of perfect square numbers that sum ton. - Example:
- Input:
n = 12 - Output:
3 - Explanation: Trace object dependencies logarithmically.
- Input:
End of Medium Journey - 20 Advanced Mixed Skills (Math + Algorithms)
380: Continuous Subarray Sum 🔴 Hard
- Problem: (Leetcode 523) Given an integer array
numsand an integerk, returntrueifnumshas a good subarray orfalseotherwise. A good subarray is a subarray where its length is at least two, and the sum of the elements of the subarray is a multiple ofk. - Example:
- Input:
nums = [23,2,4,6,7], k = 6 - Output:
true - Explanation: Format variable paths iteratively.
- Input:
381: Maximum Points You Can Obtain from Cards 🔴 Hard
- Problem: (Leetcode 1423) There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array
cardPoints. In one step, you can take one card from the beginning or from the end of the row. You have to take exactlykcards. Your score is the sum of the points of the cards you have taken. Given the integer arraycardPointsand the integerk, return the maximum score you can obtain. - Example:
- Input:
cardPoints = [1,2,3,4,5,6,1], k = 3 - Output:
12 - Explanation: Calculate minimum parameters progressively.
- Input:
382: Ugly Number II 🔴 Hard
- Problem: (Leetcode 264) An ugly number is a positive integer whose prime factors are limited to
2,3, and5. Given an integern, return then-thugly number. - Example:
- Input:
n = 10 - Output:
12 - Explanation: Check numerical configurations algorithmically.
- Input:
383: Divide and Conquer Patterns 🔴 Hard
- Problem: Practice solving problems by breaking them down into smaller subproblems, solving the subproblems recursively, and then combining their solutions. This pattern is often used efficiently with tree structures, array sorting (e.g. Merge Sort), or complex math parsing.
384: Design LRU Cache 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design LRU Cache’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design LRU Cache handles state efficiently.
- Input:
385: Design LFU Cache 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design LFU Cache’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design LFU Cache handles state efficiently.
- Input:
386: Design Tic-Tac-Toe 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Tic-Tac-Toe’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Tic-Tac-Toe handles state efficiently.
- Input:
387: Design Search Autocomplete System 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Search Autocomplete System’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Search Autocomplete System handles state efficiently.
- Input:
388: Design Log Storage System 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Log Storage System’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Log Storage System handles state efficiently.
- Input:
389: Design In-Memory File System 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design In-Memory File System’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design In-Memory File System handles state efficiently.
- Input:
390: Design Snake Game 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Snake Game’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Snake Game handles state efficiently.
- Input:
391: Design Hit Counter 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Hit Counter’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Hit Counter handles state efficiently.
- Input:
392: Design Twitter 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Twitter’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Twitter handles state efficiently.
- Input:
393: Design Parking Lot 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Parking Lot’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Parking Lot handles state efficiently.
- Input:
394: Design Elevator System 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Elevator System’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Elevator System handles state efficiently.
- Input:
395: Design Vending Machine 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Vending Machine’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Vending Machine handles state efficiently.
- Input:
396: Design BlackJack Game 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design BlackJack Game’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design BlackJack Game handles state efficiently.
- Input:
397: Design Hotel Management System 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Hotel Management System’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Hotel Management System handles state efficiently.
- Input:
398: Design Rate Limiter 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Rate Limiter’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Rate Limiter handles state efficiently.
- Input:
399: Design Consistent Hashing 🔴 Hard
- Problem: Apply Advanced OOP and System Design principles to implement ‘Design Consistent Hashing’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Design Consistent Hashing handles state efficiently.
- Input:
400: Design Tic-Tac-Toe 🔴 Hard
- Problem: (Leetcode 348) Assume the following rules are for the tic-tac-toe game on an
n x nboard between two players: A move is guaranteed to be valid and is placed on an empty block. Once a winning condition is reached, no more moves are allowed. A player who succeeds in placingnof their marks in a horizontal, vertical, or diagonal row wins the game. Implement theTicTacToeclass which initializes the object the size of the boardnand has amove(row, col, player)method. - Example:
TicTacToe(3); move(0, 0, 1); move(0, 2, 2); move(2, 2, 1); move(1, 1, 2); move(2, 0, 1); // Returns 1 (Player 1 wins)
Segment Tree & Fenwick Tree (Binary Indexed Tree)
401: Range Sum Query - Mutable 🔴 Hard
- Problem: (Leetcode 307) Given an integer array
nums, handle multiple queries of the following types: Update the value of an element innums. Calculate the sum of the elements ofnumsbetween indicesleftandrightinclusive whereleft <= right. Implement theNumArrayclass. - Example:
NumArray([1, 3, 5]); sumRange(0, 2); // return 9; update(1, 2); sumRange(0, 2); // return 8
402: Count of Smaller Numbers After Self 🔴 Hard
- Problem: (Leetcode 315) Given an integer array
nums, return an integer arraycountswherecounts[i]is the number of smaller elements to the right ofnums[i]. - Example:
- Input:
nums = [5,2,6,1] - Output:
[2,1,1,0] - Explanation: Test sequential bounds dynamically.
- Input:
403: Reverse Pairs 🔴 Hard
- Problem: (Leetcode 493) Given an integer array
nums, return the number of reverse pairs in the array. A reverse pair is a pair(i, j)where0 <= i < j < nums.lengthandnums[i] > 2 * nums[j]. - Example:
- Input:
nums = [1,3,2,3,1] - Output:
2 - Explanation: Format logical boolean matrices.
- Input:
404: Segment Tree Range Maximum Query 🔴 Hard
- Problem: Build a Segment Tree for an array to handle range maximum query and point updates in
O(log N)time. - Example:
Building a Max Segment Tree allows fetching max of interval [L, R] efficiently.
405: Range Addition 🔴 Hard
- Problem: (Leetcode 370) You are given an integer
lengthand an arrayupdateswhereupdates[i] = [startIdx, endIdx, inc]. You have an arrayarrof lengthlengthwith all zeros. Apply all updates toarrand return the finalarr. - Example:
- Input:
length = 5, updates = [[1,3,2],[2,4,3],[0,2,-2]] - Output:
[-2,0,3,5,3] - Explanation: Compute subset route variations.
- Input:
406: Falling Squares 🔴 Hard
- Problem: (Leetcode 699) There are several squares being dropped onto the X-axis of a 2D plane. You are given a 2D integer array
positions. Return an arrayanswhereans[i]is the maximum height of any square dropped after thei-thsquare is dropped. - Example:
- Input:
positions = [[1,2],[2,3],[6,1]] - Output:
[2,5,5] - Explanation: Calculate matrix sequence overlaps.
- Input:
407: Max Sum of Rectangle No Larger Than K 🔴 Hard
- Problem: (Leetcode 363) Given an
m x nmatrixmatrixand an integerk, return the max sum of a rectangle in the matrix such that its sum is no larger thank. - Example:
- Input:
matrix = [[1,0,1],[0,-2,3]], k = 2 - Output:
2 - Explanation: Return character prefix differences.
- Input:
Advanced Array Partitioning & Greedy Algorithms
408: Trapping Rain Water II 🔴 Hard
- Problem: (Leetcode 407) Given an
m x ninteger matrixheightMaprepresenting the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining. - Example:
- Input:
heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] - Output:
4 - Explanation: Format boolean configuration logic.
- Input:
409: Sliding Window Maximum 🔴 Hard
- Problem: (Leetcode 239) You are given an array of integers
nums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. - Example:
- Input:
nums = [1,3,-1,-3,5,3,6,7], k = 3 - Output:
[3,3,5,5,6,7] - Explanation: Trace shortest valid constraints.
- Input:
410: Maximum Number of Events That Can Be Attended 🔴 Hard
- Problem: (Leetcode 1353) You are given an array of
eventswhereevents[i] = [startDayi, endDayi]. Every event is represented by a start day and an end day. You can attend an eventiat any daydwherestartDayi <= d <= endDayi. You can only attend one event at any timed. Return the maximum number of events you can attend. - Example:
- Input:
events = [[1,2],[2,3],[3,4]] - Output:
3 - Explanation: Return minimal bounded configurations.
- Input:
411: Russian Doll Envelopes 🔴 Hard
- Problem: (Leetcode 354) You are given a 2D array of integers
envelopeswhereenvelopes[i] = [wi, hi]represents the width and the height of an envelope. One envelope can fit into another if and only if both the width and height of one envelope are strictly smaller than the other envelope’s width and height. Return the maximum number of envelopes you can Russian doll (i.e., put one inside the other). - Example:
- Input:
envelopes = [[5,4],[6,4],[6,7],[2,3]] - Output:
3 - Explanation: Find combination boundaries dynamically.
- Input:
412: Create Maximum Number 🔴 Hard
- Problem: (Leetcode 321) You are given two integer arrays
nums1andnums2of lengthsmandnrespectively.nums1andnums2represent the digits of two numbers. You are also given an integerk. Create the maximum number of lengthk <= m + nfrom digits of the two numbers. Output the result as an array. - Example:
- Input:
nums1 = [3,4,6,5], nums2 = [9,1,2,5,8,3], k = 5 - Output:
[9,8,6,5,3] - Explanation: Evaluate boolean configuration properties.
- Input:
413: Queue Reconstruction by Height 🔴 Hard
- Problem: (Leetcode 406) You are given an array of people,
people, which are the attributes of some people in a queue. Eachpeople[i] = [hi, ki]represents a person of heighthiwith exactlykiother people in front who have a height greater than or equal tohi. Reconstruct and return the queue that is represented by the input arraypeople. - Example:
- Input:
people = [[7,0],[4,4],[7,1],[5,0],[6,1],[5,2]] - Output:
[[5,0],[7,0],[5,2],[6,1],[4,4],[7,1]] - Explanation: Check geometric configurations algebraically.
- Input:
414: Minimum Number of Refueling Stops 🔴 Hard
- Problem: (Leetcode 871) A car travels from a starting position to a
targetposition, which is strictly to the right of the starting position. Along the way, there are gasstations. You are given the integertarget, the integerstartFuel, and the 2D integer arraystations. Return the minimum number of refueling stops the car must make in order to reach its destination. If it cannot, return-1. - Example:
- Input:
target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]] - Output:
2 - Explanation: Count maximum sequence bounds.
- Input:
Advanced Graph & Heuristic Search
415: Word Ladder II 🔴 Hard
- Problem: (Leetcode 126) A transformation sequence from word
beginWordto wordendWordusing a dictionarywordListis a sequence of wordsbeginWord -> s1 -> s2 -> ... -> sksuch that every adjacent pair of words differs by a single letter. Return all the shortest transformation sequences frombeginWordtoendWord, or an empty list if no such sequence exists. - Example:
- Input:
beginWord = "hit", endWord = "cog", wordList = ["hot","dot","dog","lot","log","cog"] - Output:
[["hit","hot","dot","dog","cog"],["hit","hot","lot","log","cog"]] - Explanation: Evaluate object sequence constraints.
- Input:
416: Sudoku Solver 🔴 Hard
- Problem: (Leetcode 37) Write a program to solve a Sudoku puzzle by filling the empty cells. A sudoku solution must satisfy the well-known rules.
- Example: Use backtracking to fill board cells safely without breaking Sudoku rules.
417: Remove Invalid Parentheses 🔴 Hard
- Problem: (Leetcode 301) Given a string
sthat contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid. Return a list of unique strings that are valid with the minimum number of removals. - Example:
- Input:
s = "()())()" - Output:
["(())()","()()()"] - Explanation: Partition continuous list coordinates.
- Input:
418: Reconstruct Itinerary 🔴 Hard
- Problem: (Leetcode 332) You are given a list of airline
ticketswheretickets[i] = [fromi, toi]represent the departure and the arrival airports of one flight. Reconstruct the itinerary in order and return it. All of the tickets belong to a man who departs from"JFK". - Example:
- Input:
tickets = [["MUC","LHR"],["JFK","MUC"],["SFO","SJC"],["LHR","SFO"]] - Output:
["JFK","MUC","LHR","SFO","SJC"] - Explanation: Calculate minimal sequential occurrences.
- Input:
419: Sliding Puzzle 🔴 Hard
- Problem: (Leetcode 773) On a
2 x 3board, there are five tiles labeled from1to5, and an empty square represented by0. A move consists of choosing0and a 4-directionally adjacent number and swapping it. Return the least number of moves required so that the state of the board is solved as[[1,2,3],[4,5,0]]. - Example:
- Input:
board = [[1,2,3],[4,0,5]] - Output:
1 - Explanation: Validate bounded subset variables.
- Input:
420: Shortest Path in a Grid with Obstacles Elimination 🔴 Hard
- Problem: (Leetcode 1293) You are given an
m x ninteger matrixgridwhere each cell is either0(empty) or1(obstacle). You can move up, down, left, or right to an empty cell in one step. You can eliminate at mostkobstacles. Return the minimum number of steps to walk from the upper left corner to the lower right corner. - Example:
- Input:
grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]], k = 1 - Output:
6 - Explanation: Find path constraint iterations.
- Input:
Arrays & Complex Data Structures
421: Find Median from Data Stream 🔴 Hard
- Problem: (Leetcode 295) The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value, and the median is the mean of the two middle values. Implement the
MedianFinderclass withaddNum(int num)andfindMedian()methods. - Example:
MedianFinder medianFinder = new MedianFinder(); medianFinder.addNum(1); medianFinder.addNum(2); medianFinder.findMedian(); // return 1.5; medianFinder.addNum(3); medianFinder.findMedian(); // return 2.0
422: Longest Valid Parentheses 🔴 Hard
- Problem: (Leetcode 32) Given a string containing just the characters
'('and')', return the length of the longest valid (well-formed) parentheses substring. - Example:
- Input:
s = ")()())" - Output:
4 - Explanation: Determine valid string subsets.
- Input:
423: Palindrome Pairs 🔴 Hard
- Problem: (Leetcode 336) You are given a 0-indexed array of unique strings
words. A palindrome pair is a pair of integers(i, j)such that0 <= i, j < words.length,i != j, andwords[i] + words[j](the concatenation of the two strings) is a palindrome. Return an array of all the palindrome pairs ofwords. - Example:
- Input:
words = ["abcd","dcba","lls","s","sssll"] - Output:
[[0,1],[1,0],[3,2],[2,4]] - Explanation: Find maximum grouping lists.
- Input:
424: The Skyline Problem 🔴 Hard
- Problem: (Leetcode 218) A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, return the skyline formed by these buildings collectively.
- Example:
- Input:
buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]] - Output:
[[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]] - Explanation: Evaluate structural dependencies procedurally.
- Input:
425: Maximal Rectangle 🔴 Hard
- Problem: (Leetcode 85) Given a
rows x colsbinary matrix filled with0’s and1’s, find the largest rectangle containing only1’s and return its area. - Example:
- Input:
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] - Output:
6 - Explanation: Calculate topological grouping.
- Input:
426: First Missing Positive 🔴 Hard
- Problem: (Leetcode 41) Given an unsorted integer array
nums, return the smallest missing positive integer. You must implement an algorithm that runs inO(n)time and usesO(1)auxiliary space. - Example:
- Input:
nums = [3,4,-1,1] - Output:
2 - Explanation: Sum dynamic variations mathematically.
- Input:
427: Missing Number 🔴 Hard
- Problem: (Leetcode 268) Given an array
numscontainingndistinct numbers in the range[0, n], return the only number in the range that is missing from the array. - Example:
- Input:
nums = [3,0,1] - Output:
2 - Explanation: Compute minimal matching limits.
- Input:
Additional Advanced Algorithms
428: K-th Smallest in Lexicographical Order 🔴 Hard
- Problem: (Leetcode 440) Given two integers
nandk, return thek-thlexicographically smallest integer in the range[1, n]. - Example:
- Input:
n = 13, k = 2 - Output:
10 - Explanation: Find bounded logic subpaths.
- Input:
429: Trapping Rain Water II 🔴 Hard
- Problem: (Leetcode 407) Given an
m x ninteger matrixheightMaprepresenting the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining. This is an advanced variation using Min-Heap. - Example:
- Input:
heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]] - Output:
4 - Explanation: Return configuration variables.
- Input:
430: Advanced Array Manipulation 🔴 Hard
- Problem: Practice solving edge cases with multi-dimensional arrays, in-place matrix modifications, and complex sliding window techniques. Use constant space variables to reduce auxiliary space complexities.
- Example:
Follow constraints and corner cases effectively in multi-dimensional states.
DP Bitmask
451: Traveling Salesperson Problem 🔴 Hard
- Problem: Given a complete graph with
nvertices (n <= 20). Find the shortest path that visits every vertex exactly once and returns to the starting vertex. - Example: Use DP with bitmask where
dp[mask][i]is the shortest path visiting the subset of vertices represented bymask, ending at vertexi.
452: Domino and Tromino Tiling 🔴 Hard
- Problem: (Leetcode 790) You have two types of tiles: a
2 x 1domino shape and a tromino shape. You may rotate these shapes. Given an integern, return the number of ways to tile an2 x nboard. Since the answer may be very large, return it modulo10^9 + 7. - Example:
- Input:
n = 3 - Output:
5 - Explanation: Parse variable constraints algorithmically.
- Input:
453: Student Attendance Record II 🔴 Hard
- Problem: (Leetcode 552) An attendance record for a student can be represented as a string where each character signifies whether the student was absent, late, or present on that day. The record only contains the following three characters:
'A','L','P'. Return the number of possible attendance records of lengthnthat make a student eligible for an attendance award. The answer may be very large, so return it modulo10^9 + 7. - Example:
- Input:
n = 2 - Output:
8 - Explanation: Return structural logic bounds.
- Input:
454: Number of Ways to Wear Different Hats to Each Other 🔴 Hard
- Problem: (Leetcode 1434) There are
npeople and40types of hats labeled from1to40. Given a 2D integer arrayhats, wherehats[i]is a list of all hats preferred by thei-thperson. Return the number of ways that thenpeople wear different hats to each other. - Example:
- Input:
hats = [[3,4],[4,5],[5]] - Output:
1 - Explanation: Count maximum iterative targets.
- Input:
455: Find Minimum Time to Finish All Jobs 🔴 Hard
- Problem: (Leetcode 1723) You are given an integer array
jobs, wherejobs[i]is the amount of time it takes to complete thei-thjob. There arekworkers that you can assign jobs to. Each job should be assigned to exactly one worker. The working time of a worker is the sum of the time it takes to complete all jobs assigned to them. Return the minimum possible maximum working time of any worker. - Example:
- Input:
jobs = [3,2,3], k = 3 - Output:
3 - Explanation: Trace cyclic bounds properly.
- Input:
456: Decode Ways II 🔴 Hard
- Problem: (Leetcode 639) A message containing letters from
A-Zcan be encoded into numbers using the mappingA -> 1,B -> 2, …,Z -> 26. Beyond that, the encoded message may also contain the character'*', which can be treated as one of the numbers from1to9. Given an encoded message stringscontaining digits and the'*'character, return the number of ways to decode it modulo10^9 + 7. - Example:
- Input:
s = "*" - Output:
9 - Explanation: Format path configuration outputs.
- Input:
Tree DP
457: Binary Tree Cameras 🔴 Hard
- Problem: (Leetcode 968) You are given the root of a binary tree. We install cameras on the tree nodes where each camera at a node can monitor its parent, itself, and its immediate children. Return the minimum number of cameras needed to monitor all nodes of the tree.
- Example:
- Input:
root = [0,0,null,0,0] - Output:
1 - Explanation: Find longest contiguous elements mathematically.
- Input:
458: House Robber III 🔴 Hard
- Problem: (Leetcode 337) The thief has found himself a new place for his thievery again. There is only one entrance to this area, called
root. Besides theroot, each house has one and only one parent house. The houses in this place form a binary tree. It will automatically contact the police if two directly-linked houses were broken into on the same night. Return the maximum amount of money the thief can rob without alerting the police. - Example:
- Input:
root = [3,2,3,null,3,null,1] - Output:
7 - Explanation: Determine boolean path layouts.
- Input:
459: Tree Diameter 🔴 Hard
- Problem: (Leetcode 1245) Given an undirected tree, return its diameter: the number of edges in a longest path in that tree.
- Example:
- Input:
edges = [[0,1],[1,2],[2,3],[1,4],[4,5]] - Output:
4 - Explanation: Filter numeric subset lists.
- Input:
460: Distribute Coins in Binary Tree 🔴 Hard
- Problem: (Leetcode 979) You are given the
rootof a binary tree withnnodes where eachnodein the tree hasnode.valcoins. There arencoins in total throughout the whole tree. In one move, we may choose two adjacent nodes and move one coin from one node to another. Return the number of moves required to make every node have exactly one coin. - Example:
- Input:
root = [3,0,0] - Output:
2 - Explanation: Compute subset combinations logarithmically. 461: Find Minimum in Rotated Sorted Array II 🔴 Hard
- Input:
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Find Minimum in Rotated Sorted Array II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find Minimum in Rotated Sorted Array II handles state efficiently.
- Input:
462: Median of Two Sorted Arrays 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Median of Two Sorted Arrays’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Median of Two Sorted Arrays handles state efficiently.
- Input:
463: Split Array Largest Sum 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Split Array Largest Sum’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Split Array Largest Sum handles state efficiently.
- Input:
464: Russian Doll Envelopes 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Russian Doll Envelopes’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Russian Doll Envelopes handles state efficiently.
- Input:
465: Super Egg Drop 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Super Egg Drop’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Super Egg Drop handles state efficiently.
- Input:
466: Allocate Minimum Number of Pages 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Allocate Minimum Number of Pages’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Allocate Minimum Number of Pages handles state efficiently.
- Input:
467: Capacity To Ship Packages Within D Days 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Capacity To Ship Packages Within D Days’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Capacity To Ship Packages Within D Days handles state efficiently.
- Input:
468: Minimum Number of Days to Make m Bouquets 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Minimum Number of Days to Make m Bouquets’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum Number of Days to Make m Bouquets handles state efficiently.
- Input:
469: Kth Smallest Number in Multiplication Table 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Kth Smallest Number in Multiplication Table’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Kth Smallest Number in Multiplication Table handles state efficiently.
- Input:
470: Find K-th Smallest Pair Distance 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Find K-th Smallest Pair Distance’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find K-th Smallest Pair Distance handles state efficiently.
- Input:
471: Minimize Max Distance to Gas Station 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Minimize Max Distance to Gas Station’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimize Max Distance to Gas Station handles state efficiently.
- Input:
472: Maximum Average Subarray II 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Maximum Average Subarray II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximum Average Subarray II handles state efficiently.
- Input:
473: Maximum Profit in Job Scheduling 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Maximum Profit in Job Scheduling’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximum Profit in Job Scheduling handles state efficiently.
- Input:
474: Minimum Limit of Balls in a Bag 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Minimum Limit of Balls in a Bag’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum Limit of Balls in a Bag handles state efficiently.
- Input:
475: Longest Increasing Subsequence 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Longest Increasing Subsequence’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Longest Increasing Subsequence handles state efficiently.
- Input:
476: Longest Valid Parentheses 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Longest Valid Parentheses’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Longest Valid Parentheses handles state efficiently.
- Input:
477: Edit Distance 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Edit Distance’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Edit Distance handles state efficiently.
- Input:
478: Regular Expression Matching 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Regular Expression Matching’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Regular Expression Matching handles state efficiently.
- Input:
479: Wildcard Matching 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Wildcard Matching’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Wildcard Matching handles state efficiently.
- Input:
480: Distinct Subsequences 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Distinct Subsequences’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Distinct Subsequences handles state efficiently.
- Input:
481: Interleaving String 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Interleaving String’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Interleaving String handles state efficiently.
- Input:
482: Maximal Rectangle 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Maximal Rectangle’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximal Rectangle handles state efficiently.
- Input:
483: Maximal Square 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Maximal Square’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximal Square handles state efficiently.
- Input:
484: Palindrome Partitioning II 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Palindrome Partitioning II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Palindrome Partitioning II handles state efficiently.
- Input:
485: Burst Balloons 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Burst Balloons’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Burst Balloons handles state efficiently.
- Input:
486: Scramble String 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Scramble String’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Scramble String handles state efficiently.
- Input:
487: Word Break II 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Word Break II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Word Break II handles state efficiently.
- Input:
488: Coin Change II 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Coin Change II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Coin Change II handles state efficiently.
- Input:
489: Target Sum 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Target Sum’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Target Sum handles state efficiently.
- Input:
490: Minimum ASCII Delete Sum for Two Strings 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Minimum ASCII Delete Sum for Two Strings’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum ASCII Delete Sum for Two Strings handles state efficiently.
- Input:
491: Minimum Output to Make Array Sorted 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Minimum Output to Make Array Sorted’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum Output to Make Array Sorted handles state efficiently.
- Input:
492: Count Different Palindromic Subsequences 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Count Different Palindromic Subsequences’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Count Different Palindromic Subsequences handles state efficiently.
- Input:
493: Student Attendance Record II 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Student Attendance Record II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Student Attendance Record II handles state efficiently.
- Input:
494: Maximum Number of Dart Points 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Maximum Number of Dart Points’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximum Number of Dart Points handles state efficiently.
- Input:
495: Largest Rectangle in Histogram 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Largest Rectangle in Histogram’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Largest Rectangle in Histogram handles state efficiently.
- Input:
496: Trapping Rain Water 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Trapping Rain Water’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Trapping Rain Water handles state efficiently.
- Input:
497: Optimal Binary Search Tree 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Optimal Binary Search Tree’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Optimal Binary Search Tree handles state efficiently.
- Input:
498: Maximum Subarray Sum with One Deletion 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Maximum Subarray Sum with One Deletion’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximum Subarray Sum with One Deletion handles state efficiently.
- Input:
499: Frog Jump 🔴 Hard
- Problem: Solve the problem using Advanced DP and/or Binary Search: ‘Frog Jump’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Frog Jump handles state efficiently.
- Input:
500: Advanced Logic & Graph Mastery 🔴 Hard
- Problem: Final challenge blending Graph algorithms, advanced DP states, and optimized memory usage. Revisit the toughest algorithm puzzles requiring multiple layered techniques.
Strings, KMP, Trie & Suffix Arrays
501: Implement KMP (String Matching) 🔴 Hard
- Problem: (Leetcode 28) Implement the Knuth-Morris-Pratt (KMP) algorithm to find the first occurrence of a substring in a string. Create the LPS (Longest Prefix Suffix) table to match the pattern in the string efficiently in
O(N)time. - Example:
- Input:
haystack = "hello", needle = "ll" - Output:
2 - Explanation: Verify matrix sequences efficiently.
- Input:
502: Shortest Palindrome 🔴 Hard
- Problem: (Leetcode 214) You are given a string
s. You can convertsto a palindrome by adding characters in front of it. Return the shortest palindrome you can find by performing this transformation. - Example:
- Input:
s = "aacecaaa" - Output:
"aaacecaaa" - Explanation: Test consecutive logical boundaries.
- Input:
503: Word Search II 🔴 Hard
- Problem: (Leetcode 212) Given an
m x nboardof characters and a list of stringswords, return all words on the board. Each word must be constructed from letters of sequentially adjacent cells. Use a Trie to store the words and perform DFS on the board to find valid words efficiently. - Example:
- Input:
board = [["o","a","a","n"],["e","t","a","e"],["i","h","k","r"],["i","f","l","v"]], words = ["oath","pea","eat","rain"] - Output:
["eat","oath"] - Explanation: Format character iterations systematically.
- Input:
504: Distinct Echo Substrings 🔴 Hard
- Problem: (Leetcode 1316) Return the number of distinct non-empty substrings of
textthat can be written as the concatenation of some string with itself (i.e., it can be written asa + awhereais some string). Use Rolling Hash (Rabin-Karp) for string matching. - Example:
- Input:
text = "abcabcabc" - Output:
3 - Explanation: Extract optimal matrix limits efficiently.
- Input:
505: Longest Duplicate Substring 🔴 Hard
- Problem: (Leetcode 1044) Given a string
s, consider all duplicated substrings: (contiguous) substrings ofsthat occur 2 or more times. The occurrences may overlap. Return any duplicated substring that has the longest possible length. - Example:
- Input:
s = "banana" - Output:
"ana" - Explanation: Compute maximum topological combinations. 506: Longest Palindromic Substring 🔴 Hard
- Input:
- Problem: Solve the advanced string algorithm: ‘Longest Palindromic Substring’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Longest Palindromic Substring.
- Input:
507: Regular Expression Matching 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Regular Expression Matching’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Regular Expression Matching.
- Input:
508: Longest Valid Parentheses 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Longest Valid Parentheses’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Longest Valid Parentheses.
- Input:
509: Wildcard Matching 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Wildcard Matching’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Wildcard Matching.
- Input:
510: Distinct Subsequences 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Distinct Subsequences’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Distinct Subsequences.
- Input:
511: Word Ladder II 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Word Ladder II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Word Ladder II.
- Input:
512: Word Ladder 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Word Ladder’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Word Ladder.
- Input:
513: Palindrome Partitioning II 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Palindrome Partitioning II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Palindrome Partitioning II.
- Input:
514: Word Break II 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Word Break II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Word Break II.
- Input:
515: Shortest Palindrome 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Shortest Palindrome’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Shortest Palindrome.
- Input:
516: Remove Invalid Parentheses 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Remove Invalid Parentheses’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Remove Invalid Parentheses.
- Input:
517: Palindrome Pairs 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Palindrome Pairs’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Palindrome Pairs.
- Input:
518: Concatenated Words 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Concatenated Words’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Concatenated Words.
- Input:
519: Find All Anagrams in a String 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Find All Anagrams in a String’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find All Anagrams in a String.
- Input:
520: Minimum Window Substring 🔴 Hard
- Problem: Solve the advanced string algorithm: ‘Minimum Window Substring’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum Window Substring.
- Input:
Advanced Math, Binary Search & Greedy Algorithms
521: Candy 🔴 Hard
- Problem: (Leetcode 135) There are
nchildren standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. Return the minimum number of candies you need to have to distribute the candies to the children. - Example:
- Input:
ratings = [1,0,2] - Output:
5 - Explanation: Trace bounds over overlapping groupings.
- Input:
522: Best Meeting Point 🔴 Hard
- Problem: (Leetcode 296) Given an
m x nbinary gridgridwhere each1marks the home of one friend, return the minimum total travel distance. The total travel distance is the sum of the distances between the houses of the friends and the meeting point. Find the median in both dimensions to minimize Manhattan distance. - Example:
- Input:
grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]] - Output:
6 - Explanation: Determine valid object parameters.
- Input:
523: Minimum Number of Days to Make m Bouquets 🔴 Hard
- Problem: (Leetcode 1482) You are given an integer array
bloomDay, an integermand an integerk. You want to makembouquets. To make a bouquet, you need to usekadjacent flowers from the garden. Return the minimum number of days you need to wait to be able to makembouquets from the garden. - Example:
- Input:
bloomDay = [1,10,3,10,2], m = 3, k = 1 - Output:
3 - Explanation: Find maximum logic arrays.
- Input:
524: Maximum Points on a Line 🔴 Hard
- Problem: (Leetcode 149) Given an array of
pointswherepoints[i] = [xi, yi]represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line. - Example:
- Input:
points = [[1,1],[2,2],[3,3]] - Output:
3 - Explanation: Evaluate structured lists systematically.
- Input:
525: Split Array Largest Sum 🔴 Hard
- Problem: (Leetcode 410) Given an integer array
numsand an integerk, splitnumsintoknon-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. - Example:
- Input:
nums = [7,2,5,10,8], k = 2 - Output:
18 - Explanation: Calculate generic mapping logically. 526: Median of Two Sorted Arrays 🔴 Hard
- Input:
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Median of Two Sorted Arrays’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Median of Two Sorted Arrays.
- Input:
527: Reverse Integer 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Reverse Integer’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Reverse Integer.
- Input:
528: String to Integer (atoi) 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘String to Integer (atoi)’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for String to Integer (atoi).
- Input:
529: Palindrome Number 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Palindrome Number’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Palindrome Number.
- Input:
530: Divide Two Integers 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Divide Two Integers’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Divide Two Integers.
- Input:
531: Permutation Sequence 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Permutation Sequence’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Permutation Sequence.
- Input:
532: Valid Number 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Valid Number’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Valid Number.
- Input:
533: Sqrt(x) 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Sqrt(x)’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Sqrt(x).
- Input:
534: Search in Rotated Sorted Array 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Search in Rotated Sorted Array’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Search in Rotated Sorted Array.
- Input:
535: Search in Rotated Sorted Array II 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Search in Rotated Sorted Array II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Search in Rotated Sorted Array II.
- Input:
536: Find Minimum in Rotated Sorted Array 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Find Minimum in Rotated Sorted Array’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find Minimum in Rotated Sorted Array.
- Input:
537: Find Minimum in Rotated Sorted Array II 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Find Minimum in Rotated Sorted Array II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find Minimum in Rotated Sorted Array II.
- Input:
538: Find Peak Element 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Find Peak Element’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find Peak Element.
- Input:
539: Koko Eating Bananas 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Koko Eating Bananas’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Koko Eating Bananas.
- Input:
540: Split Array Largest Sum 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Split Array Largest Sum’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Split Array Largest Sum.
- Input:
541: Find K-th Smallest Pair Distance 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Find K-th Smallest Pair Distance’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Find K-th Smallest Pair Distance.
- Input:
542: Minimize Max Distance to Gas Station 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Minimize Max Distance to Gas Station’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimize Max Distance to Gas Station.
- Input:
543: Allocate Minimum Number of Pages 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Allocate Minimum Number of Pages’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Allocate Minimum Number of Pages.
- Input:
544: Capacity To Ship Packages Within D Days 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Capacity To Ship Packages Within D Days’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Capacity To Ship Packages Within D Days.
- Input:
545: Minimum Number of Days to Make m Bouquets 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Minimum Number of Days to Make m Bouquets’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum Number of Days to Make m Bouquets.
- Input:
546: Kth Smallest Number in Multiplication Table 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Kth Smallest Number in Multiplication Table’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Kth Smallest Number in Multiplication Table.
- Input:
547: Maximum Average Subarray II 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Maximum Average Subarray II’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximum Average Subarray II.
- Input:
548: Maximum Profit in Job Scheduling 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Maximum Profit in Job Scheduling’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Maximum Profit in Job Scheduling.
- Input:
549: Minimum Limit of Balls in a Bag 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Minimum Limit of Balls in a Bag’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Minimum Limit of Balls in a Bag.
- Input:
550: Preimage Size of Factorial Zeroes Function 🔴 Hard
- Problem: Solve the advanced mathematical / binary search algorithm: ‘Preimage Size of Factorial Zeroes Function’.
- Example:
- Input:
... - Output:
... - Explanation: Implementation logic for Preimage Size of Factorial Zeroes Function.
- Input:
System Design & Data Structures
551: LFU Cache 🔴 Hard
- Problem: (Leetcode 460) Design and implement a data structure for a Least Frequently Used (LFU) cache. Implement the
LFUCacheclass withget(int key)andput(int key, int value). - Example: Evict the least frequently used keys in
O(1)time when capacity is reached.
552: Design Search Autocomplete System 🔴 Hard
- Problem: (Leetcode 642) Design a search autocomplete system for a search engine. Users may input a sentence (at least one word and end with a special character
'#'). For each character they type except'#', you need to return the top 3 historical hot sentences that have prefix the same as the part of sentence already typed. - Example: Use Trie and sorting to quickly retrieve frequent matches.
553: Design In-Memory File System 🔴 Hard
- Problem: (Leetcode 588) Design a data structure that simulates an in-memory file system. Implement the
FileSystemclass withls,mkdir,addContentToFile, andreadContentFromFilemethods. - Example: Use a Trie-like structure or hierarchical hash maps to store directories and files.
554: Design Ticket Booking System 🔴 Hard
- Problem: Design a fast booking system to assign seats, check availability, and cancel bookings efficiently. Implement mechanisms to process frequent seat requests.
- Example: Use Priority Queue or sets for logarithmic specific queries.
555: Design Snake Game 🔴 Hard
- Problem: (Leetcode 353) Design a Snake game that is played on a device with screen size
height x width. Play the game online if you wish, can show you the description. The snake is initially positioned at the top left corner(0, 0)with a length of1unit. - Example: Track snake body parts using a Queue and a HashSet for
O(1)collision detection.
State Machines & Hard Logic Puzzles
556: Alien Dictionary 🔴 Hard
- Problem: (Leetcode 269) 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
wordsfrom the alien language’s dictionary, where the strings inwordsare sorted lexicographically by the rules of this new language. Return a string of the unique letters in the new alien language sorted in lexicographically increasing order. - Example:
- Input:
["wrt","wrf","er","ett","rftt"] - Output:
"wertf" - Explanation: Format path configuration mathematically.
- Input:
557: Word Squares 🔴 Hard
- Problem: (Leetcode 425) Given an array of unique strings
words, return all the word squares you can build fromwords. A sequence of words forms a valid word square if thek-throw and column read the exact same string. - Example:
- Input:
["area","lead","wall","lady","ball"] - Output:
[["wall","area","lead","lady"], ["ball","area","lead","lady"]] - Explanation: Find optimal parameter configurations.
- Input:
558: Maximum Flow / Ford-Fulkerson 🔴 Hard
- Problem: Given a flow network, find the maximum possible flow from source to sink. Implement the Ford-Fulkerson method (or Edmonds-Karp) to locate augmenting paths in the residual graph.
- Example: A complex graph algorithm mapping network capacity constraints and bottlenecks.
559: Maximal Rectangle 🔴 Hard
- Problem: (Leetcode 85) Given a
rows x colsbinarymatrixfilled with0’s and1’s, find the largest rectangle containing only1’s and return its area. - Example:
- Input:
matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]] - Output:
6 - Explanation: Check graph sequence bounds.
- Input:
560: Burst Balloons 🔴 Hard
- Problem: (Leetcode 312) You are given
nballoons, indexed from0ton - 1. Each balloon is painted with a number on it represented by an arraynums. You are asked to burst all the balloons. Return the maximum coins you can collect by bursting the balloons wisely. - Example:
- Input:
nums = [3,1,5,8] - Output:
167 - Explanation: Compute minimum tree depth algorithmically.
- Input:
561: Remove Invalid Parentheses 🔴 Hard
- Problem: (Leetcode 301) Given a string
sthat contains parentheses and letters, remove the minimum number of invalid parentheses to make the input string valid. Return all the possible results. You may return the answer in any order. - Example:
- Input:
s = "()())()" - Output:
["(())()","()()()"] - Explanation: Verify bounded tree boundaries.
- Input:
562: Regular Expression Matching 🔴 Hard
- Problem: (Leetcode 10) Given an input string
sand a patternp, implement regular expression matching with support for.and*. - Example:
- Input:
s = "ab", p = ".*" - Output:
true - Explanation: Analyze overlapping string segments efficiently.
- Input:
563: Wildcard Matching 🔴 Hard
- Problem: (Leetcode 44) Given an input string
sand a patternp, implement wildcard pattern matching with support for?and*. - Example:
- Input:
s = "adceb", p = "*a*b" - Output:
true - Explanation: Analyze recursive targets properly.
- Input:
564: Substring with Concatenation of All Words 🔴 Hard
- Problem: (Leetcode 30) You are given a string
sand an array of stringswords. All the strings ofwordsare of the same length. Return all starting indices of substring(s) insthat is a concatenation of each word inwordsexactly once, in any order, and without any intervening characters. - Example:
- Input:
s = "barfoothefoobarman", words = ["foo","bar"] - Output:
[0,9] - Explanation: Format character properties functionally.
- Input:
565: Largest Rectangle in Histogram 🔴 Hard
- Problem: (Leetcode 84) Given an array of integers
heightsrepresenting the histogram’s bar height where the width of each bar is1, return the area of the largest rectangle in the histogram. - Example:
- Input:
heights = [2,1,5,6,2,3] - Output:
10 - Explanation: Calculate parameter constraints quickly.
- Input:
566: N-Queens 🔴 Hard
- Problem: (Leetcode 51) The n-queens puzzle is the problem of placing
nqueens on ann x nchessboard such that no two queens attack each other. Given an integern, return all distinct solutions to the n-queens puzzle. - Example:
- Input:
n = 4 - Output:
[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]] - Explanation: Search elements iterating dynamically.
- Input:
567: Sliding Window Maximum 🔴 Hard
- Problem: (Leetcode 239) You are given an array of integers
nums, there is a sliding window of sizekwhich is moving from the very left of the array to the very right. You can only see theknumbers in the window. Each time the sliding window moves right by one position. Return the max sliding window. - Example:
- Input:
nums = [1,3,-1,-3,5,3,6,7], k = 3 - Output:
[3,3,5,5,6,7] - Explanation: Analyze bounded array subsets logarithmically.
- Input:
568: Edit Distance 🔴 Hard
- Problem: (Leetcode 72) Given two strings
word1andword2, return the minimum number of operations required to convertword1toword2. You have the following three operations permitted on a word: Insert a character, Delete a character, Replace a character. - Example:
- Input:
word1 = "horse", word2 = "ros" - Output:
3 - Explanation: Format boolean structure limits.
- Input:
569: Distinct Subsequences 🔴 Hard
- Problem: (Leetcode 115) Given two strings
sandt, return the number of distinct subsequences ofswhich equalst. - Example:
- Input:
s = "rabbbit", t = "rabbit" - Output:
3 - Explanation: Evaluate mathematical matrices efficiently.
- Input:
570: Interleaving String 🔴 Hard
- Problem: (Leetcode 97) Given strings
s1,s2, ands3, find whethers3is formed by an interleaving ofs1ands2. - Example:
- Input:
s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac" - Output:
true - Explanation: Compute valid subset distributions continuously.
- Input:
571: Best Time to Buy and Sell Stock III 🔴 Hard
- Problem: (Leetcode 123) You are given an array
priceswhereprices[i]is the price of a given stock on thei-thday. Find the maximum profit you can achieve. You may complete at most two transactions. - Example:
- Input:
prices = [3,3,5,0,0,3,1,4] - Output:
6 - Explanation: Identify object string dependencies algebraically.
- Input:
572: Best Time to Buy and Sell Stock IV 🔴 Hard
- Problem: (Leetcode 188) You are given an integer array
priceswhereprices[i]is the price of a given stock on thei-thday, and an integerk. Find the maximum profit you can achieve. You may complete at mostktransactions. - Example:
- Input:
k = 2, prices = [3,2,6,5,0,3] - Output:
7 - Explanation: Find maximum configuration dependencies.
- Input:
573: Palindrome Partitioning II 🔴 Hard
- Problem: (Leetcode 132) Given a string
s, partitionssuch that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning ofs. - Example:
- Input:
s = "aab" - Output:
1 - Explanation: Compute numerical grouping constraints.
- Input:
574: Russian Doll Envelopes 🔴 Hard
- Problem: (Leetcode 354) You are given a 2D array of integers
envelopeswhereenvelopes[i] = [w_i, h_i]represents the width and the height of an envelope. One envelope can fit into another if and only if both the width and height of one envelope are strictly smaller than the other. Return the maximum number of envelopes you can Russian doll. - Example:
- Input:
envelopes = [[5,4],[6,4],[6,7],[2,3]] - Output:
3 - Explanation: Evaluate geometric matrix bounds continuously.
- Input:
575: Insert Interval 🔴 Hard
- Problem: (Leetcode 57) You are given an array of non-overlapping intervals
intervalswhereintervals[i] = [start_i, end_i]represent the start and the end of thei-thinterval andintervalsis sorted in ascending order bystart_i. You are also given an intervalnewInterval. InsertnewIntervalintointervals. - Example:
- Input:
intervals = [[1,3],[6,9]], newInterval = [2,5] - Output:
[[1,5],[6,9]] - Explanation: Compute continuous iteration dependencies.
- Input:
576: Find Median from Data Stream 🔴 Hard
- Problem: (Leetcode 295) The median is the middle value in an ordered integer list. Implement the
MedianFinderclass withaddNum(int num)andfindMedian()methods. - Example:
MedianFinder mf = new MedianFinder(); mf.addNum(1); mf.addNum(2); mf.findMedian(); // 1.5; mf.addNum(3); mf.findMedian(); // 2.0
577: Number of Digit One 🔴 Hard
- Problem: (Leetcode 233) Given an integer
n, count the total number of digit1appearing in all non-negative integers less than or equal ton. - Example:
- Input:
n = 13 - Output:
6 - Explanation: Solve mapping boundaries functionally.
- Input:
578: Minimum Window Substring 🔴 Hard
- Problem: (Leetcode 76) Given two strings
sandtof lengthsmandnrespectively, return the minimum window substring ofssuch that every character int(including duplicates) is included in the window. - Example:
- Input:
s = "ADOBECODEBANC", t = "ABC" - Output:
"BANC" - Explanation: Optimize parameter boundaries successfully.
- Input:
579: Trapping Rain Water 🔴 Hard
- Problem: (Leetcode 42) Given
nnon-negative integers representing an elevation map where the width of each bar is1, compute how much water it can trap after raining. - Example:
- Input:
height = [0,1,0,2,1,0,1,3,2,1,2,1] - Output:
6 - Explanation: Trace generic matrix constraints securely.
- Input:
580: First Missing Positive 🔴 Hard
- Problem: (Leetcode 41) Given an unsorted integer array
nums. Return the smallest positive integer that is not present innums. You must implement an algorithm that runs inO(n)time and usesO(1)auxiliary space. - Example:
- Input:
nums = [3,4,-1,1] - Output:
2 - Explanation: Format bounds using algebraic functions.
- Input:
581: K-th Smallest in Lexicographical Order 🔴 Hard
- Problem: (Leetcode 440) Given two integers
nandk, return thek-thlexicographically smallest integer in the range[1, n]. - Example:
- Input:
n = 13, k = 2 - Output:
10 - Explanation: Calculate numerical list matches logically.
- Input:
582: Basic Calculator 🔴 Hard
- Problem: (Leetcode 224) Given a string
srepresenting a valid expression, implement a basic calculator to evaluate it, and return the result of the evaluation. Supports+,-,(,). - Example:
- Input:
s = "(1+(4+5+2)-3)+(6+8)" - Output:
23 - Explanation: Check boolean grouping sets procedurally.
- Input:
583: Count of Smaller Numbers After Self 🔴 Hard
- Problem: (Leetcode 315) Given an integer array
nums, return an integer arraycountswherecounts[i]is the number of smaller elements to the right ofnums[i]. - Example:
- Input:
nums = [5,2,6,1] - Output:
[2,1,1,0] - Explanation: Find continuous coordinate mappings automatically.
- Input:
584: Split Array Largest Sum 🔴 Hard
- Problem: (Leetcode 410) Given an integer array
numsand an integerk, splitnumsintoknon-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. - Example:
- Input:
nums = [7,2,5,10,8], k = 2 - Output:
18 - Explanation: Return structural property limits securely.
- Input:
585: Scramble String 🔴 Hard
- Problem: (Leetcode 87) We can scramble a string
sto get a stringtusing a specific algorithm. Given two stringss1ands2of the same length, returntrueifs2is a scrambled string ofs1, otherwise, returnfalse. - Example:
- Input:
s1 = "great", s2 = "rgeat" - Output:
true - Explanation: Calculate generic subset limits optimally.
- Input:
586: Merge k Sorted Lists 🔴 Hard
- Problem: (Leetcode 23) You are given an array of
klinked-listslists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. - Example:
- Input:
lists = [[1,4,5],[1,3,4],[2,6]] - Output:
[1,1,2,3,4,4,5,6] - Explanation: Format numerical structure sequences.
- Input:
587: Reverse Nodes in k-Group 🔴 Hard
- Problem: (Leetcode 25) Given the
headof a linked list, reverse the nodes of the listkat a time, and return the modified list. - Example:
- Input:
head = [1,2,3,4,5], k = 2 - Output:
[2,1,4,3,5] - Explanation: Validate looping property subsets dynamically.
- Input:
588: Serialize and Deserialize Binary Tree 🔴 Hard
- Problem: (Leetcode 297) Design an algorithm to serialize and deserialize a binary tree. There is no restriction on how your serialization/deserialization algorithm should work.
- Example:
- Input:
root = [1,2,3,null,null,4,5] - Output:
"[1,2,3,null,null,4,5]" - Explanation: Compute continuous array coordinates computationally.
- Input:
589: Binary Tree Maximum Path Sum 🔴 Hard
- Problem: (Leetcode 124) 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. Given the
rootof a binary tree, return the maximum path sum of any non-empty path. - Example:
- Input:
root = [-10,9,20,null,null,15,7] - Output:
42 - Explanation: Translate parameter boolean mappings safely.
- Input:
590: Vertical Order Traversal of a Binary Tree 🔴 Hard
- Problem: (Leetcode 987) Given the
rootof a binary tree, calculate the vertical order traversal of the binary tree. - Example:
- Input:
root = [1,2,3,4,5,6,7] - Output:
[[4],[2],[1,5,6],[3],[7]] - Explanation: Format numerical boundaries precisely and gracefully.
- Input:
591: Longest Validity Parentheses 🔴 Hard
- Problem: (Leetcode 32) Given a string containing just the characters
'('and')', return the length of the longest valid (well-formed) parentheses substring. - Example:
- Input:
s = ")()())" - Output:
4 - Explanation: Compute bound sequence arrays correctly.
- Input:
592: Find All People With Secret 🔴 Hard
- Problem: (Leetcode 2092) You are given an integer
nindicating there arenpeople numbered from0ton - 1. You are also given a 0-indexed 2D integer arraymeetingswheremeetings[i] = [x_i, y_i, time_i]indicates that personx_iand persony_ihave a meeting attime_i. A secret is initially shared with person0and personfirstPersonat time0. Return a list of all the people that have the secret after all the meetings have taken place. - Example:
- Input:
n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1 - Output:
[0,1,2,3,5] - Explanation: Evaluate overlapping parameters effectively.
- Input:
593: Race Car 🔴 Hard
- Problem: (Leetcode 818) Your car starts at position
0and speed+1on an infinite number line. Your car can go into negative positions. Your car drives automatically according to a sequence of instructions'A'(accelerate) and'R'(reverse). Find the length of the shortest sequence of instructions to get there. - Example:
- Input:
target = 3 - Output:
2 ("AA") - Explanation: Return sequential logic properties successfully.
- Input:
594: Max Value of Equation 🔴 Hard
- Problem: (Leetcode 1499) You are given an array
pointscontaining the coordinates of points on a 2D plane, sorted by the x-values, wherepoints[i] = [x_i, y_i], and an integerk. Return the maximum value of the equationy_i + y_j + |x_i - x_j|where|x_i - x_j| <= kand1 <= i < j <= points.length. - Example:
- Input:
points = [[1,3],[2,0],[5,10],[6,-10]], k = 1 - Output:
4 - Explanation: Identify bounded dependencies algorithmically.
- Input:
595: Parse Lisp Expression 🔴 Hard
- Problem: (Leetcode 736) You are given a string
expressionrepresenting a Lisp-like expression to return the integer value of. - Example:
- Input:
expression = "(let x 2 (mult x (let x 3 y 4 (add x y))))" - Output:
14 - Explanation: Locate variable array matrices securely.
- Input:
596: Kth Smallest Number in Multiplication Table 🔴 Hard
- Problem: (Leetcode 668) Nearly everyone has used the Multiplication Table. Given the height
mand the lengthnof am x nMultiplication Table, and a positive integerk, return thek-thsmallest number in the table. - Example:
- Input:
m = 3, n = 3, k = 5 - Output:
3 - Explanation: Return sequence path dependencies functionally.
- Input:
597: Remove 9 🔴 Hard
- Problem: (Leetcode 660) Start from integer
1, remove any integer that contains9such as9,19,29… So now, you will have a new integer sequence[1, 2, 3, 4, 5, 6, 7, 8, 10, 11, ...]. Given an integern, return then-th(1-indexed) integer in the new sequence. - Example:
- Input:
n = 9 - Output:
10 - Explanation: Trace logic distributions successfully and securely.
- Input:
598: Max Points on a Line 🔴 Hard
- Problem: (Leetcode 149) Given an array of
pointswherepoints[i] = [x_i, y_i]represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line. - Example:
- Input:
points = [[1,1],[2,2],[3,3]] - Output:
3 - Explanation: Evaluate looping structures systematically.
- Input:
599: Robot Room Cleaner 🔴 Hard
- Problem: (Leetcode 427) You are controlling a robot that is located somewhere in a room. The room is modeled as an
m x ngrid. You may not know the dimensions of the room. Design an algorithm to clean the entire room using only the 4 given APIs. - Example: DFS with backtracking mapped onto relative coordinates.
600: The Final Challenge 🔴 Hard
- Problem: Culminating multi-layered algorithmic problem requiring a fusion of advanced Dynamic Programming, Trie optimizations, and Segment trees. Mastering this validates complete readiness for any software engineering interview.