Problem · Sliding Window
Longest OR
Learn this problemProblem statement
There is an array of n integers, arr, and two integers mn and mx.
For each of arr's subarrays, find the binary value of the bitwise OR of all elements. If the number of 1 bits is between mn and mx, inclusive, it's a good subarray.
Determine the length of the longest good subarray.
Note: A subarray is any segment of adjacent elements in an array. For example, if arr = [1, 2, 3], [1, 2] is a subarray but [1, 3] is not.
Function
longestGoodSubarray(arr: int[], mn: int, mx: int) → int
Complete the function longestGoodSubarray in the editor.
longestGoodSubarray has the following parameters:
int arr[n]: an array of integersint mn: an integerint mx: an integer
Returns
int: the length of the longest good subarray
Examples
Example 1
arr = [0, 3, 4, 1, 5]mn = 1mx = 2return = 3No explanation is provided for now. And I am not 100% sure about the output of this example. If you find it wrong, you are very welcome to let me know, and I will fix it right away. Many many thanks in advance! 🧡🧡
Cheers,
Groot 🛵
Constraints
Unknown so far. If you happen to know about it, feel free to contact Groot in our server. TYVM!More Tiktok problems
- Count Access Code PairsOA · Seen Jul 2026
- Count Key ChangesOA · Seen Jul 2026
- Travel Distance on ScootersOA · Seen Jul 2026
- Count Skipped Numbers After SubtractionsOA · Seen Jul 2026
- Obstacle Placement QueriesOA · Seen Jul 2026
- Repeated Grouped Digit SumOA · Seen Jul 2026
- Count Cyclic Digit PairsOA · Seen Jun 2026
- Event ID Check Completion TimesOA · Seen Jun 2026