Skip to content

Commit c28a653

Browse files
author
hasibulislam999
committed
Longest Subarray With Maximum Bitwise AND problem solved
1 parent d72bab9 commit c28a653

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Title: Longest Subarray With Maximum Bitwise AND
3+
* Description: You are given an integer array nums of size n.
4+
* Author: Hasibul Islam
5+
* Date: 15/04/2023
6+
*/
7+
8+
/**
9+
* @param {number[]} nums
10+
* @return {number}
11+
*/
12+
var longestSubarray = function (nums) {
13+
const maxVal = Math.max(...nums);
14+
let result = 1;
15+
16+
let outcome = 0;
17+
for (const val of nums.values()) {
18+
if (val === maxVal) {
19+
outcome++;
20+
result = Math.max(result, outcome);
21+
} else {
22+
outcome = 0;
23+
}
24+
}
25+
26+
return result;
27+
};

0 commit comments

Comments
 (0)