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.
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.
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.
5 7 1 2 3 4 5
2
You need to login to view your submissions.
You need to login to view all submissions.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.