Skip to content

Commit c8f3b0e

Browse files
committed
2275. Largest Combination With Bitwise AND Greater Than Zero: RETRY
1 parent 84239b9 commit c8f3b0e

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,3 +1723,4 @@ mod s2271_maximum_white_tiles_covered_by_a_carpet;
17231723
mod s2272_substring_with_largest_variance;
17241724
mod s2273_find_resultant_array_after_removing_anagrams;
17251725
mod s2274_maximum_consecutive_floors_without_special_floors;
1726+
mod s2275_largest_combination_with_bitwise_and_greater_than_zero;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* [2275] Largest Combination With Bitwise AND Greater Than Zero
3+
*
4+
* The bitwise AND of an array nums is the bitwise AND of all integers in nums.
5+
*
6+
* For example, for nums = [1, 5, 3], the bitwise AND is equal to 1 & 5 & 3 = 1.
7+
* Also, for nums = [7], the bitwise AND is 7.
8+
*
9+
* You are given an array of positive integers candidates. Compute the bitwise AND for all possible combinations of elements in the candidates array.
10+
* Return the size of the largest combination of candidates with a bitwise AND greater than 0.
11+
*
12+
* Example 1:
13+
*
14+
* Input: candidates = [16,17,71,62,12,24,14]
15+
* Output: 4
16+
* Explanation: The combination [16,17,62,24] has a bitwise AND of 16 & 17 & 62 & 24 = 16 > 0.
17+
* The size of the combination is 4.
18+
* It can be shown that no combination with a size greater than 4 has a bitwise AND greater than 0.
19+
* Note that more than one combination may have the largest size.
20+
* For example, the combination [62,12,24,14] has a bitwise AND of 62 & 12 & 24 & 14 = 8 > 0.
21+
*
22+
* Example 2:
23+
*
24+
* Input: candidates = [8,8]
25+
* Output: 2
26+
* Explanation: The largest combination [8,8] has a bitwise AND of 8 & 8 = 8 > 0.
27+
* The size of the combination is 2, so we return 2.
28+
*
29+
*
30+
* Constraints:
31+
*
32+
* 1 <= candidates.length <= 10^5
33+
* 1 <= candidates[i] <= 10^7
34+
*
35+
*/
36+
pub struct Solution {}
37+
38+
// problem: https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/
39+
// discuss: https://leetcode.com/problems/largest-combination-with-bitwise-and-greater-than-zero/discuss/?currentPage=1&orderBy=most_votes&query=
40+
41+
// submission codes start here
42+
43+
impl Solution {
44+
pub fn largest_combination(candidates: Vec<i32>) -> i32 {
45+
0
46+
}
47+
}
48+
49+
// submission codes end
50+
51+
#[cfg(test)]
52+
mod tests {
53+
use super::*;
54+
55+
#[test]
56+
#[ignore]
57+
fn test_2275_example_1() {
58+
let candidates = vec![16, 17, 71, 62, 12, 24, 14];
59+
60+
let result = 4;
61+
62+
assert_eq!(Solution::largest_combination(candidates), result);
63+
}
64+
65+
#[test]
66+
#[ignore]
67+
fn test_2275_example_2() {
68+
let candidates = vec![8, 8];
69+
70+
let result = 2;
71+
72+
assert_eq!(Solution::largest_combination(candidates), result);
73+
}
74+
}

0 commit comments

Comments
 (0)