int ans=0;
while(n!=0){
int temp=dc/x;
ans+=temp;
n-=temp;
dc=dc%x;
if(n!=0){
n--;
dc+=y;
}
}
System.out.println(ans);
int ans=0;
while(n!=0){
int temp=dc/x;
ans+=temp;
n-=temp;
dc=dc%x;
if(n!=0){
n--;
dc+=y;
}
}
System.out.println(ans);
@Vipin_coder,
I see that you have correctly submitted the question.
Do you have any further queries regarding the same?
yes , i want to ask my approach is wrong or not optimized , that i have posted here
@Vipin_coder,
The approach you’ve posted here is not optimized.
The approach you’ve submitted is correct and optimized
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.