GOLDMANSACHS Coding Question – Solved

5 Live
A traveler is traveling from the city of Zeta to Omega. He starts with X amount of money. Every day he spends some money and may also work on certain days to earn money. On some days, he may earn more than he spends, and on other days, he may spend more than he earns. You are given an array of integers, which represents his net savings (earnings - expenses) on any day. Your task is to find out the minimum amount the traveler should begin with to ensure that he always has some money (> 0) at the end of any day. Constraints: - -200 <= a <= 200, where `a` are the elements of the array. - 0 < i <= 100, where `i` is the array length. - X >= 0 Example: Input: 3 // Array length 4 // Array elements start 2 -3 Output: 0 Explanation: Traveler saves $4 on the first day, $2 on the second day, and $-3 on the third day (expenses are more on the third day than earnings). - End of the first day, he has X + $4. - End of the second day, he has X + $(4 + 2). - End of the third day, he has X + $(4 + 2 - 3). So, effectively, the traveler can start with X = $0 to always ensure he has some money at the end of each day.

Asked in: GOLDMANSACHS

Image of the Question

Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Given an n x m grid, where rows are numbered from 7 to n and columns from 1 to … |
| There are 'N' coders standing in a line, where i denotes the ith position of a … |
| A birthday party was attended by N number of kids, and each kid was given a uni… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |
| As an operations engineer at Amazon, you are responsible for organizing the dis… |
| Given a matrix of size m * n, where m denotes the number of rows (starting with… |