English, asked by shubhamvb99, 4 months ago

Write a program for Minimum withdrawals
There is a unique ATM in Wonderland. Imagine this ATM as an array of numbers. You can only withdraw cash from either
end of the array, Sarah wants to withdraw X amount of cash from the ATM. What are the minimum number of withdrawals
Sarah would need to accumulate X amount of cash If it is not po Wble for Sarah to withdraw X amount, return -1.
Function Description
Complete the minimumWithdrawal function in the editor below. It has the following parameter(s):
Parameters
Name
Type
Description
N
INTEGER
The size of ATM array
- 500
ATM
INTEGER ARRAY
The given ATM
X
INTEGER
Amount to withdraw
The function must return an INTEGER denoting the Minimum
number of withdrawals if it is not possible return -1
Constraints
O program​

Answers

Answered by subarna0182
1

Answer:

give me my answer

Explanation:

cnjkkfdkvcfgjvfddjvxv

Answered by dreamrob
0

Program in C++:

#include <bits/stdc++.h>

using namespace std;

int l;

 

int Min(int ll,int h,int amount,vector<int> A)

{

   if(amount==0) return 0;

   if(ll>h || amount<0) return l;

   return min(1+Min(ll+1,h,amount-A[ll],A),1+Min(ll,h-1,amount-A[h],A));

}

 

int main()

{

   int N;

   cout<<"Enter total number elements : ";

cin>>N;

   vector<int> A(N);

   cout<<"\nEnter all the amounts : \n";

   for(int i=0; i<N; i++)  

{

 cin>>A[i];

}

int amount;

cout<<"\nEnter amount to withdraw : ";

cin>>amount;

   l=pow(10,9);

   int no=Min(0,N-1,amount,A);

   if(no >= l)

{

 cout<<endl<<-1;

}

   else  

{

 cout<<"\nMinimum number of withdrawals : "<<no;

}

return 0;

}

Output:

Enter total number elements : 5

Enter all the amounts :

10

20

30

40

50

Enter amount to withdraw : 30

Minimum number of withdrawals : 2

Similar questions