AlgoUniversity
  • Go Back
Discussion
The Abandoned City :

Author

Yash Sahijwani

Difficulty Level : Easy

Submissions : 516

Asked In : Barclays

Marks :10

: 5 | : 0

You have bought virtual reality glasses. There is only one game installed in it "The Abandoned City". In the game, you are lost in an abandoned city and need to collect atleast k number of coins, to exit the city and win the game. However, currently you don't have any coins. Thankfully, there are $$$n$$$ houses in the city, arranged in a line, numbered from 1 to n, where the $$$i_{th}$$$ house has $$$a[i]$$$ coins. You need to collect coins from the houses by starting at any house in the line and moving either to the left or to the right, but you can't change your direction after starting. You need to find the minimum number of houses you need to visit to get atleast k coins, given that you can start at any house.

Input

The first line consists of 2 integers $$$-$$$ $$$n$$$ and $$$k$$$ where $$$n$$$ is the total number of houses in the city, and $$$k$$$ is the total number of coins required by you to win the game. The second line consists of $$$n$$$ space separated integers where the $$$i_{th}$$$ number is $$$a[i]$$$, the number of coins in the $$$i_{th}$$$ city.

Output

You need to output a single integer, the minimum number of houses you need to visit in order to get atleast $$$k$$$ coins. If you can't collect atleast $$$k$$$ coins, output -1.

Example

Input
5 7
1 2 3 4 5
Output
2

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.