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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |