LeetCode 3825 — Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND
Автор: CodingHelp
Загружено: 2026-02-02
Просмотров: 16
Описание:
LeetCode 3825 — Longest Strictly Increasing Subsequence With Non-Zero Bitwise AND
From Biweekly Contest 175
Problem Summary:
You are given an array nums.
You must find the length of the longest strictly increasing subsequence
whose bitwise AND of all elements is non-zero.
If no such subsequence exists, return 0.
Example:
[5,4,7] → answer = 2
because subsequence [5,7] has AND = 5 (non-zero)
Why this problem is tricky:
It looks like a normal LIS problem…
but with an extra bitwise constraint.
Brute force and DP explode quickly and cause TLE.
Key Insight:
For AND to stay non-zero,
at least one bit must remain 1 across all chosen elements.
So we flip the thinking:
Instead of choosing subsequences directly,
we choose a bit that must survive.
Strategy:
For each bit position (0 → 31):
1. Filter numbers that contain that bit
2. Run Longest Increasing Subsequence (LIS)
3. Take the maximum LIS length
This converts exponential search
into an efficient O(32 × n log n) solution.
Concepts used:
✔ Bit manipulation
✔ Longest Increasing Subsequence
✔ Greedy optimization
✔ Contest strategy thinking
✔ Pattern recognition
This is a perfect interview question combining
LIS + bit tricks + optimization insight.
Java implementation explained step-by-step in the video.
Subscribe for daily contest breakdowns and interview hacks:
DSA | Java | LeetCode | Competitive Programming
#leetcode3825 #biweekly175 #coding #dsa #java #lis #bitmanipulation #shorts
#leetcode3825 #biweekly175 #leetcodecontest #coding #dsa #java #lis #bitmanipulation #shorts #coding #codinghelp
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: