3825. Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND Medium

@problem@discussion
#Array#Binary Search#Bit Manipulation#Enumeration



1/**
2 * [3825] Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND
3 *
4 * You are given an integer array nums.
5 * Return the length of the longest strictly increasing <span data-keyword="subsequence-array-nonempty">subsequence</span> in nums whose bitwise AND is non-zero. If no such subsequence exists, return 0.
6 *  
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">nums = [5,4,7]</span>
10 * Output: <span class="example-io">2</span>
11 * Explanation:
12 * One longest strictly increasing subsequence is [5, 7]. The bitwise AND is 5 AND 7 = 5, which is non-zero.
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">nums = [2,3,6]</span>
17 * Output: <span class="example-io">3</span>
18 * Explanation:
19 * The longest strictly increasing subsequence is [2, 3, 6]. The bitwise AND is 2 AND 3 AND 6 = 2, which is non-zero.
20 * </div>
21 * <strong class="example">Example 3:
22 * <div class="example-block">
23 * Input: <span class="example-io">nums = [0,1]</span>
24 * Output: <span class="example-io">1</span>
25 * Explanation:
26 * One longest strictly increasing subsequence is [1]. The bitwise AND is 1, which is non-zero.
27 * </div>
28 *  
29 * Constraints:
30 * 
31 * 	1 <= nums.length <= 10^5
32 * 	0 <= nums[i] <= 10^9​​​​​​​
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/longest-strictly-increasing-subsequence-with-non-zero-bitwise-and/
38// discuss: https://leetcode.com/problems/longest-strictly-increasing-subsequence-with-non-zero-bitwise-and/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn longest_subsequence(nums: Vec<i32>) -> i32 {
44        0
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_3825() {
56    }
57}
58

Back
© 2026 bowen.ge All Rights Reserved.