I understood this question but unable to proceed with the implementation part. Can you please help me with that.
Pattern 110 : Digit DP
did you try the naive solution?
the naive solution can be run a loop from L to R, and check in every number if 110 exists in its binary form , if yes , count++.
how to check for 110 in a number?
while(n){
int x = n&1;
if(x==0){
//wrote your code to check for two consecutive 1’s. }
n= n>>1;
}
then think of a better solution by establishing some relationship of binary form between two consecutive numbers.
thanks
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.