2025-10-27
2125. Number of Laser Beams in a Bank
Topic: Array, Math, String, Matrix
Difficulty: Medium
Problem:
Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array
There is one laser beam between any two security devices if both conditions are met:
• The two devices are located on two different rows:
• For each row
Laser beams are independent, i.e., one beam does not interfere nor join with another.
Return the total number of laser beams in the bank.
Example 1:
Image: https://assets.leetcode.com/uploads/2021/12/24/laser1.jpg
Example 2:
Image: https://assets.leetcode.com/uploads/2021/12/24/laser2.jpg
Constraints:
•
•
•
•
  2125. Number of Laser Beams in a Bank
Topic: Array, Math, String, Matrix
Difficulty: Medium
Problem:
Anti-theft security devices are activated inside a bank. You are given a 0-indexed binary string array
bank representing the floor plan of the bank, which is an m x n 2D matrix. bank[i] represents the i^th row, consisting of '0's and '1's. '0' means the cell is empty, while'1' means the cell has a security device.There is one laser beam between any two security devices if both conditions are met:
• The two devices are located on two different rows:
r_1 and r_2, where r_1 < r_2.• For each row
i where r_1 < i < r_2, there are no security devices in the i^th row.Laser beams are independent, i.e., one beam does not interfere nor join with another.
Return the total number of laser beams in the bank.
Example 1:
Image: https://assets.leetcode.com/uploads/2021/12/24/laser1.jpg
Input: bank = ["011001","000000","010100","001000"]
Output: 8
Explanation: Between each of the following device pairs, there is one beam. In total, there are 8 beams:
* bank[0][1] -- bank[2][1]
* bank[0][1] -- bank[2][3]
* bank[0][2] -- bank[2][1]
* bank[0][2] -- bank[2][3]
* bank[0][5] -- bank[2][1]
* bank[0][5] -- bank[2][3]
* bank[2][1] -- bank[3][2]
* bank[2][3] -- bank[3][2]
Note that there is no beam between any device on the 0^th row with any on the 3^rd row.
This is because the 2^nd row contains security devices, which breaks the second condition.
Example 2:
Image: https://assets.leetcode.com/uploads/2021/12/24/laser2.jpg
Input: bank = ["000","111","000"]
Output: 0
Explanation: There does not exist two devices located on two different rows.
Constraints:
•
m == bank.length•
n == bank[i].length•
1 <= m, n <= 500•
bank[i][j] is either '0' or '1'.2025-10-28
3354. Make Array Elements Equal to Zero
Topic: Array, Simulation, Prefix Sum
Difficulty: Easy
Problem:
You are given an integer array
Start by selecting a starting position
After that, you repeat the following process:
• If
• If
• Else if
• Decrement
• Reverse your movement direction (left becomes right and vice versa).
• Take a step in your new direction.
A selection of the initial position
Return the number of possible valid selections.
Example 1:
Input: nums = 1,0,2,0,3
Output: 2
Explanation:
The only possible valid selections are the following:
• Choose
•
• Choose
•
Example 2:
Input: nums = 2,3,4,0,4,1,0
Output: 0
Explanation:
There are no possible valid selections.
Constraints:
•
•
• There is at least one element
  3354. Make Array Elements Equal to Zero
Topic: Array, Simulation, Prefix Sum
Difficulty: Easy
Problem:
You are given an integer array
nums.Start by selecting a starting position
curr such that nums[curr] == 0, and choose a movement direction of either left or right.After that, you repeat the following process:
• If
curr is out of the range [0, n - 1], this process ends.• If
nums[curr] == 0, move in the current direction by incrementing curr if you are moving right, or decrementing curr if you are moving left.• Else if
nums[curr] > 0:• Decrement
nums[curr] by 1.• Reverse your movement direction (left becomes right and vice versa).
• Take a step in your new direction.
A selection of the initial position
curr and movement direction is considered valid if every element in nums becomes 0 by the end of the process.Return the number of possible valid selections.
Example 1:
Input: nums = 1,0,2,0,3
Output: 2
Explanation:
The only possible valid selections are the following:
• Choose
curr = 3, and a movement direction to the left.•
[1,0,2,0,3] -> [1,0,2,0,3] -> [1,0,1,0,3] -> [1,0,1,0,3] -> [1,0,1,0,2] -> [1,0,1,0,2] -> [1,0,0,0,2] -> [1,0,0,0,2] -> [1,0,0,0,1] -> [1,0,0,0,1] -> [1,0,0,0,1] -> [1,0,0,0,1] -> [0,0,0,0,1] -> [0,0,0,0,1] -> [0,0,0,0,1] -> [0,0,0,0,1] -> [0,0,0,0,0].• Choose
curr = 3, and a movement direction to the right.•
[1,0,2,0,3] -> [1,0,2,0,3] -> [1,0,2,0,2] -> [1,0,2,0,2] -> [1,0,1,0,2] -> [1,0,1,0,2] -> [1,0,1,0,1] -> [1,0,1,0,1] -> [1,0,0,0,1] -> [1,0,0,0,1] -> [1,0,0,0,0] -> [1,0,0,0,0] -> [1,0,0,0,0] -> [1,0,0,0,0] -> [0,0,0,0,0].Example 2:
Input: nums = 2,3,4,0,4,1,0
Output: 0
Explanation:
There are no possible valid selections.
Constraints:
•
1 <= nums.length <= 100•
0 <= nums[i] <= 100• There is at least one element
i where nums[i] == 0.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.