Question 8: Minimum Withdrawals

Minimum Withdrawals

Today we will discuss InfyTQ Coding question that is Minimum withdrawals that was asked in InfyTQ Coding question InfyTQ Advance Coding Section. We will see the Question description along with function description and the Test Cases along with there explanation.

You will find the solution of the problem which is asked for InfyTQ Coding question in various programming language. 

Minimum withdraw Infytq

 

Problem Statement-: There is a unique ATM in Wonderland. Imagine this ATM as an array of numbers. You can withdraw cash only from either ends of the array. Sarah wants to withdraw X amount of cash from the ATM. What is the minimum number of withdrawals Sarah would need to accumulate X amount of cash. If it is not possible for Sarah to withdraw X amount, return -1. 

Input Format 

  • The first line contains an integer, N, denoting the number of elements in ATM. 
  • Each line i of the N subsequent lines (where 0 <= i < N) contains an integer describing the cash in the ATM. 
  • The next line contains an integer, X, denoting the total amount to withdraw. 

Constraints 

  • 1 <= N <= 10^5 
  • 1 <= ATM [i] <= 10^5 
  • 1 <= X <= 10^5 

Sample Test Cases

  • Sample Input
    2
    1
    1
  • Sample Output
    -1 
  • Explanation
    The total amount of cash in the ATM is 2, hence Sarah cannot withdraw an amount of 3.