MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / longestNiceSubarray

Method longestNiceSubarray

LongestNiceSubarray.java:2–17  ·  view source on GitHub ↗
(int[] nums)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int longestNiceSubarray(int[] nums) {
3 int start=0;
4 int maxLen=0;
5 int bitMask=0;
6 int n = nums.length;
7 for(int end=0;end<n;end++){
8 //shrinking
9 while((bitMask & nums[end]) != 0){
10 bitMask = bitMask ^ nums[start];
11 start++;
12 }
13 bitMask = bitMask | nums[end];
14 maxLen = Math.max(maxLen, end - start +1);
15 }
16 return maxLen;
17 }
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected