அல்கோரிதம்advanced
Advanced Binary Search
TT
Testlaa Team
May 14, 2026•1 min read
Advanced: segment tree, graph, DP state space கூட binary search — monotone + check.
Try this in Python
def first_position_bit_pattern(n: int) -> int:
"""Toy: smallest i in [0,n) where (i ^ (i>>1)) & 1 == 0 — pattern demo only."""
lo, hi = 0, n
while lo < hi:
mid = (lo + hi) // 2
ok = ((mid ^ (mid >> 1)) & 1) == 0
if ok:
hi = mid
else:
lo = mid + 1
return lo
print(first_position_bit_pattern(20))
Key takeaways
- Advanced =
checkகடினம்; loop அடிப்படையே. - Monotonicity paper-இல்.
bisectபயன்படுத்து.
Tags:
Binary searchPythonமாணவர்கள்
