Author: Editorial Team
-
Problem 705: Design HashSet
You must design your own HashSet data structure from scratch.It should support the following operations efficiently: add(key)remove(key)contains(key) You are NOT allowed to use built-in HashSet libraries. The input range of keys is typically from 0 to 1,000,000. Understanding the Problem HashSet stores unique integers with fast O(1) operations. You need to implement: void add(int key)void…
-
Problem 520: Detect Capital
You are given a word, and you must determine whether the usage of capital letters is correct based on the following rules: A word is correctly capitalized if: Any word that violates these three patterns is incorrect. Your task is to return true if the capitalization is valid, false otherwise. Understanding the Problem Examples: Input:…
-
Problem 70: Climbing Stairs
You are climbing a staircase with n steps.Each time you can take either 1 step or 2 steps.Your task is to return how many distinct ways you can reach the top. Understanding the Problem If n = 1Ways = 1(Only one move of 1 step) If n = 2Ways = 2(1+1)(2) If n = 3Ways…
-
Problem 140: Word Break II
You are given a string s and a list of words wordDict.You must return all possible sentences where s can be segmented such that each segment is a word in the dictionary. Unlike Word Break I (Problem 139), where you return true/false, here you must return all valid combinations. Understanding the Problem Example: s =…
-
Problem 309: Best Time to Buy and Sell Stock with Cooldown
You are given an array prices where prices[i] is the stock price on day i.You may complete as many transactions as you want, but after selling, you must wait one cooldown day before buying again. Your task:Return the maximum profit possible. Understanding the Problem You can: Buy one shareSell one shareNot hold multiple sharesCooldown: after…
-
Problem 621: Task Scheduler
You are given: An array of CPU tasks, each represented by an uppercase letterA non-negative cooling interval n The CPU can execute one task per unit time, but the same task must have at least n units of cooling time before it can run again. Your goal:Return the minimum number of time intervals needed to…
-
Problem 258: Add Digits
You are given a non-negative integer num.Your task is to repeatedly add all its digits until only one digit remains. This final single digit is also known as the digital root. Understanding the Problem You repeatedly sum the digits of the number: Example:num = 383 + 8 = 111 + 1 = 2So the answer…
-
Problem 25: Reverse Nodes in k-Group
You are given the head of a linked list and an integer k.Your task is to reverse the nodes of the list k at a time, and return the modified list. If the number of nodes remaining at the end is less than k, leave them as-is. Understanding the Problem Example: Input: 1 → 2…
-
Problem 258: Add Digits
Given a non-negative integer num, you must repeatedly add all its digits until only one digit remains. This is known as the digital root of a number. Example: Input: 383 + 8 = 111 + 1 = 2Output = 2 Understanding the Problem You repeatedly sum the digits of a number: If the number has…
-
Problem 154: Find Minimum in Rotated Sorted Array II
This is a follow-up to LeetCode 153, but with one important difference: The rotated sorted array may contain duplicates. Example: Input: [2,2,2,0,1]Output: 0 Because duplicates exist, the classic binary-search logic from problem 153 does not work directly and needs modification. Understanding the Problem The array is: SortedRotated at some pivotContains duplicates Goal: return the minimum…
