Please check my java code and tell me why all test cases are not working
Hello @Bhuwan-Agrawal-2362769150606526,
You can refer to this video by Prateek Bhaiya.
He has explained the logic for this problem at 1:55:12.
If you still don’t understand your mistake.
Let me know, I will help you in correcting your code.
hello Sir I have seen the video but stil donot understand my mistake
I have seen the video but still cant understand whaat’s wrong with my code;
Hello @Bhuwan-Agrawal-2362769150606526,
Mistake:
You have computed the ans from the leftmost index of the string.
Solution:
You have to iterate the loop from the rightmost index.
Corrected Code:
Hope, this would help.
Give a like if you are satisfied.
Sir now the code is working fine but according to the video where ever we encounter 7 the no. of digits less than that would be 2 raised to power index where index is starting from 0???
Hey @Bhuwan-Agrawal-2362769150606526,
Please, watch the video again.
You might have misunderstood it.
The reason to iterate from right most position:
rightmost digit refers to the ones position.
and so on while moving towards to left.
You can refer to this video for better understanding.
now I understand thanks