Let $P(x)$ be the total number of digits '$4$' in the number $x$.
For instance:
$X= 19$: $P(19)=0$ since $19$ does not contain any digit $4$
$X=1234$: $P(1243)=1$
$X=441240$: $P(441270)=3$
$X=4444211344$: $P(44424211344)=6$
$X=12367$: $P(12367)=0$
Similarly, let $Q(x)$ be the total number of digits '$7$' in the number $x$.
For example:
$X=765217$: $Q(x)=2$
$X=12378$: $Q(x)=1$
$X=777777444477$: $Q(x)=8$
We are given the two values $A$ and $B$.We have to find
$\max(P(x) * Q(x) :: A \leq X \leq B)$
Example 1:
A= 1 B=100
(MAX(P(x) * Q(x) :: A <= X <= B) is Answer=1.
Note:
{Acheived at X=47}
Note It is also achieved when Value of X is following:
X=47
X=74
Example 2.
A= 51 B=1000
(MAX(P(x) * Q(x) :: A <= X <= B) is Answer=2.
Note:
{Acheived at X=447}
Note It is also achieved when Value of X is following:
X=447
X=474
X=477
X=744
X=747
X=774
Example 3:
A= 4123 B=9432
(MAX(P(x) * Q(x) :: A <= X <= B) is Answer=4.
Note:
{Acheived at X=4477}
Note It is also achieved when Value of X is following:
X=4477
X=4747
X=4774
X=7447
X=7474
X=7744
Example 4:
A= 2222 B=2400
(MAX(P(x) * Q(x) :: A <= X <= B) is Answer=1.
Note:
{Acheived at X=2247}
Note
It is also achieved when Value of X is following:
X=2247
X=2274
X=2347
X=2374
Note : We just need to calculate the maximum product ie.Answer is the maximum product .
No need to calculate at what value of x it occurs .
Also ,Found this question while practising algorithm problems.
The constraint is Large
1 ≤ A ≤ B≤ 10^19
Tried brute force ,but it was indeed slow.So what is the efficient way Thanks!