Longest OR

Longest OR

FULLTIME

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 Description

Complete the function longestGoodSubarray in the editor.

longestGoodSubarray has the following parameters:

  1. int arr[n] : an array of integers
  2. int mn : an integer
  3. int mx : an integer


Returns

int : the length of the longest good subarray


Example 1 :

Input: arr = [0, 3, 4, 1, 5], mn = 1, mx = 2
Output: 3




Get one-to-one training from Google Facebook engineers

Top-notch Professionals

Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.

Customized Private Class

Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.