2025-10-29
3370. Smallest Number With All Set Bits
Topic: Math, Bit Manipulation
Difficulty: Easy
Problem:
You are given a positive number
Return the smallest number
Example 1:
Input: n = 5
Output: 7
Explanation:
The binary representation of 7 is
Example 2:
Input: n = 10
Output: 15
Explanation:
The binary representation of 15 is
Example 3:
Input: n = 3
Output: 3
Explanation:
The binary representation of 3 is
Constraints:
•
3370. Smallest Number With All Set Bits
Topic: Math, Bit Manipulation
Difficulty: Easy
Problem:
You are given a positive number
n.Return the smallest number
x greater than or equal to n, such that the binary representation of x contains only set bitsExample 1:
Input: n = 5
Output: 7
Explanation:
The binary representation of 7 is
"111".Example 2:
Input: n = 10
Output: 15
Explanation:
The binary representation of 15 is
"1111".Example 3:
Input: n = 3
Output: 3
Explanation:
The binary representation of 3 is
"11".Constraints:
•
1 <= n <= 10002025-10-30
1526. Minimum Number of Increments on Subarrays to Form a Target Array
Topic: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
Difficulty: Hard
Problem:
You are given an integer array
In one operation you can choose any subarray from
Return the minimum number of operations to form a
The test cases are generated so that the answer fits in a 32-bit integer.
Example 1:
Example 2:
Example 3:
Constraints:
•
•
1526. Minimum Number of Increments on Subarrays to Form a Target Array
Topic: Array, Dynamic Programming, Stack, Greedy, Monotonic Stack
Difficulty: Hard
Problem:
You are given an integer array
target. You have an integer array initial of the same size as target with all elements initially zeros.In one operation you can choose any subarray from
initial and increment each value by one.Return the minimum number of operations to form a
target array from initial.The test cases are generated so that the answer fits in a 32-bit integer.
Example 1:
Input: target = [1,2,3,2,1]
Output: 3
Explanation: We need at least 3 operations to form the target array from the initial array.
[0,0,0,0,0] increment 1 from index 0 to 4 (inclusive).
[1,1,1,1,1] increment 1 from index 1 to 3 (inclusive).
[1,2,2,2,1] increment 1 at index 2.
[1,2,3,2,1] target array is formed.
Example 2:
Input: target = [3,1,1,2]
Output: 4
Explanation: [0,0,0,0] -> [1,1,1,1] -> [1,1,1,2] -> [2,1,1,2] -> [3,1,1,2]
Example 3:
Input: target = [3,1,5,4,2]
Output: 7
Explanation: [0,0,0,0,0] -> [1,1,1,1,1] -> [2,1,1,1,1] -> [3,1,1,1,1] -> [3,1,2,2,2] -> [3,1,3,3,2] -> [3,1,4,4,2] -> [3,1,5,4,2].
Constraints:
•
1 <= target.length <= 10^5•
1 <= target[i] <= 10^52025-10-31
3289. The Two Sneaky Numbers of Digitville
Topic: Array, Hash Table, Math
Difficulty: Easy
Problem:
In the town of Digitville, there was a list of numbers called
As the town detective, your task is to find these two sneaky numbers. Return an array of size two containing the two numbers (in any order), so peace can return to Digitville.
Example 1:
Input: nums = 0,1,1,0
Output: 0,1
Explanation:
The numbers 0 and 1 each appear twice in the array.
Example 2:
Input: nums = 0,3,2,1,3,2
Output: 2,3
Explanation:
The numbers 2 and 3 each appear twice in the array.
Example 3:
Input: nums = 7,1,5,4,3,4,6,0,9,5,8,2
Output: 4,5
Explanation:
The numbers 4 and 5 each appear twice in the array.
Constraints:
•
•
•
• The input is generated such that
3289. The Two Sneaky Numbers of Digitville
Topic: Array, Hash Table, Math
Difficulty: Easy
Problem:
In the town of Digitville, there was a list of numbers called
nums containing integers from 0 to n - 1. Each number was supposed to appear exactly once in the list, however, two mischievous numbers sneaked in an additional time, making the list longer than usual.As the town detective, your task is to find these two sneaky numbers. Return an array of size two containing the two numbers (in any order), so peace can return to Digitville.
Example 1:
Input: nums = 0,1,1,0
Output: 0,1
Explanation:
The numbers 0 and 1 each appear twice in the array.
Example 2:
Input: nums = 0,3,2,1,3,2
Output: 2,3
Explanation:
The numbers 2 and 3 each appear twice in the array.
Example 3:
Input: nums = 7,1,5,4,3,4,6,0,9,5,8,2
Output: 4,5
Explanation:
The numbers 4 and 5 each appear twice in the array.
Constraints:
•
2 <= n <= 100•
nums.length == n + 2•
0 <= nums[i] < n• The input is generated such that
nums contains exactly two repeated elements.2025-11-01
3217. Delete Nodes From Linked List Present in Array
Topic: Array, Hash Table, Linked List
Difficulty: Medium
Problem:
You are given an array of integers
Example 1:
Input: nums = 1,2,3, head = 1,2,3,4,5
Output: 4,5
Explanation:
Image: https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png
Remove the nodes with values 1, 2, and 3.
Example 2:
Input: nums = 1, head = 1,2,1,2,1,2
Output: 2,2,2
Explanation:
Image: https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png
Remove the nodes with value 1.
Example 3:
Input: nums = 5, head = 1,2,3,4
Output: 1,2,3,4
Explanation:
Image: https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png
No node has value 5.
Constraints:
•
•
• All elements in
• The number of nodes in the given list is in the range
•
• The input is generated such that there is at least one node in the linked list that has a value not present in
3217. Delete Nodes From Linked List Present in Array
Topic: Array, Hash Table, Linked List
Difficulty: Medium
Problem:
You are given an array of integers
nums and the head of a linked list. Return the head of the modified linked list after removing all nodes from the linked list that have a value that exists in nums.Example 1:
Input: nums = 1,2,3, head = 1,2,3,4,5
Output: 4,5
Explanation:
Image: https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample0.png
Remove the nodes with values 1, 2, and 3.
Example 2:
Input: nums = 1, head = 1,2,1,2,1,2
Output: 2,2,2
Explanation:
Image: https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample1.png
Remove the nodes with value 1.
Example 3:
Input: nums = 5, head = 1,2,3,4
Output: 1,2,3,4
Explanation:
Image: https://assets.leetcode.com/uploads/2024/06/11/linkedlistexample2.png
No node has value 5.
Constraints:
•
1 <= nums.length <= 10^5•
1 <= nums[i] <= 10^5• All elements in
nums are unique.• The number of nodes in the given list is in the range
[1, 10^5].•
1 <= Node.val <= 10^5• The input is generated such that there is at least one node in the linked list that has a value not present in
nums.