so i found this cool leetcode problem: binary number with alternating bits - 693. it's about checking if a num's bin rep has adjacent bit flips without loops.
basically, you're given an int and need to return true only when the nums in its binary form alternate between zeros & ones (e. g, '10' or even long like.
"452687394".
).
i tried it out with c++, python + js. turns tricky but super fun! i used bitwise ops and some clever tricks to make the solution work.
so, here's a quick take:
- use `&` & bit shifting
- check if flips match pattern
anyone else played around w/ this one? how'd it go for you?
ps: wondering about best ways to test these kinds of problems. any tips or gotchas?
gotcha : watch out for edge cases like single-digit nums!
https://dev.to/om_shree_0709/beginner-friendly-guide-binary-number-with-alternating-bits-leetcode-693-c-python-2aco