Answered step by step
Verified Expert Solution
Question
1 Approved Answer
How many expenses must be rescheduled to the end of the year so that the company doesn't fall into debt? Task description A company has
How many expenses must be rescheduled to the end of the year so that the company doesn't fall into debt?
Task description
A company has a list of expected revenues and payments for the upcoming year in chronological order.
The problem is that at some moments in time the sum of previous payments can be larger than the total previous revenue.
This would put the company in debt. To avoid this problem the company takes a very simple approach. It reschedules some expenses to the end of the year.
You are given an array of integers, where positive numbers represent revenues and negative numbers represent expenses, all in chronological order.
In one move you can relocate any expense negative number to the end of the array.
What is the minimum number of such relocations to make sure that the company never falls into debt? In other words:
you need to make sure that there is no consecutive sequence of elements starting from the beginning of the array, that sums up to a negative number.
You can assume that the sum of all elements in A is nonnegative.
Write a function:
function solutionA;
that, given an array A of N integers, returns the minimum number of relocations, so that company never falls into debt.
Examples:
Given A the function should return It is enough to move to the end of the array.
Given A the function should return
The negative elements at the beginning must be moved to the end to avoid debt at the start of the year.
Given A the function should return The company balance is always nonnegative.
Write an efficient algorithm for the following assumptions:
N is an integer within the range ;
each element of array A is an integer within the range ;
sum of all elements in A is greater than or equal to
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started