LOVE BABBAR 450 questions series

We have completed strings.
Thanks for sticking around so far.
Like, share and subscribe.

Hats off to your dedication man. Like this, you will complete all 450 problems within 1-2 months along with helping others. Really appreciate your good work.

1 Like

Thanks a lot brother.
Please share the channel with all your friends and subscribe to the channel.
It will really motivate me.
All the best for your future endeavour.

1 Like

Check out this small announcement and be supportive.
It will help me grow and also benefit you all in one way or the other.

Not satisfied but got best rank till date.

If you have upsolved 2nd problem for full points, please make a video on that. I really like your way of explanations.

I shall definitely try very soon.
Thanks

1 Like

You can just calculate all the boring numbers till (and including) R and similarly till L and subtract them.
To calculate all boring numbers till X (say)-
Iterate through 1 to len(X)-1.
If i is the curr length, then the count of boring numbers of that length can be given by 5^i because each place has 5 options.
Now tough task is to count the boring numbers of length len(X). Now we have an upper bound of X.
Now we’ll iterate through each digit of X from left to right. Say we encounter the first digit as 5. If we choose 5 at first position, we will have restrictions on the next positions. So, for the time being I only consider odd values less than 5. Say, that equals to val. So, count of boring numbers with the first position less than 5 and odd can be calculated as (5^{l-1} \cdot val) if l is the length of the X. Now consider fixing the first number as 5 and repeat the same procedure for next digits.
Just as an example to make clear. Say the number is something like 56....
We fix 5 now number of choices of first place is 1, for second place is 3 (0,2,4) and for the rest of l-2 places we have 5 choices without restrictions and in next iteration we’ll fix 6 and so on…
One thing more, Say we get a number like 57... Since second place is 7 and we want it to be even, we will not calculate the second part of answer by fixing 7 and will break the loop.

Code Snippet
b=len(r) # r is any number in its string format and b is length of the string
c=0
for i in r:
c^=1
val=0
for j in range(int(i)-1,-1,-1):
if j%2==c:
val+=1
ans+=(5**(b-1))*val
if int(i)%2!=c%2:
break
b-=1

1 Like

Don’t we require digit dp for full points?

Sorry, I don’t know what digit dp actually is. My solution is O(length) where length can be at max 18. I just used simple rule of product in combo.

sorting and searching has started.
Like share and subscribe.

Thank you all.
Share the channel with all your friends.
Subscribe if you have not yet!.

Try to code the last problem by yourself first and then check my solution for reference.
Like,share and subscribe.

Last problem has 6 different approaches.
I suggest you to go and find out atleast 2 to 3 more.
Like, share and subscribe.

Please watch this video and tell me if their is a logical approach and an ideal one.

First question is asked in interviews frequently.
That’s what everyone says.
Check it out!.
Like share and subscribe.

Try the homework problem by referring to the easier version of the same concept(2sum,3sum)
Like share and subscribe.