TRIPLET OF AND

Given an array of integers A of size N.

Return an array B of size 2, where

B[0] = max( A[i] & A[j] & A[k]) where i < j < k and '&' is bitwise AND operator.
B[1] = (No. of triplets (i,j,k) where i < j < k having value B[0]) % 10^9+7. <br> **Input Format**

The only argument given is the integer array A.

Output Format

Return an array B of size 2, where

    B[0] = max( A[i] & A[j] & A[k]) where i < j < k and '&' is bitwise AND operator.
    B[1] = (No. of triplets (i,j,k) where i < j < k having value B[0]) % 10^9+7.

Constraints

3 <= N <= 10^5
1 <= A[i] <= 10^9 

For Example

Example Input 1:
    A = [1, 2, 3, 4, 5, 6]
Example Output 1:
    B = [4, 1]
Example Explanation 1:
    Consider Triplet (4, 5, 6)
    4 & 5 & 6 = 4
    Number of triplets having 4 as and are only1 i.e. (4, 5, 6)

Example Input 2:
    A = [37720, 44104, 72864, 50729, 50170]
Example Output 2:
    B = [33288, 1]
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving TRIPLET OF AND on Interview Code Editor
Sign Up
to access hints and editorial solutions for TRIPLET OF AND

Discussion


Loading...
Click here to start solving coding interview questions