Ask Question
20 February, 06:28

github Portfolio Balances An investor opens a new account and wants to invest in a number of assets. Each asset begins with a balance of o, and its value is stored in an array using 7-based indexing. Periodically, a contribution is received and equal investments are made in a subset of the portfolio. Each contribution will be given by investment amount, start index, end index. Each investment in that range will receive the contribution amount. Determine the maximum amount invested in any one investment after all contributions

+2
Answers (1)
  1. 20 February, 09:34
    0
    The following code will be used to determine the maximum amount invested

    Explanation:

    long maxValue (int n, int rounds_rows, int rounds_columns, int into rounds)

    {

    / / Define the variable to store

    / / the maximum amount invested.

    long max = 0;

    / / Define an array of size n,

    / / to store the n investments.

    long * investments = (long*) malloc (sizeof (long) * n);

    int i=0;

    / / Initially set all

    / / the investments to 0.

    for (i=0; i
    {

    investments[i] = 0;

    }

    i=0;

    / / Run the loop to

    / / perform the rounds.

    while (i
    {

    / / Get the left value

    / / of the current round.

    int left = rounds[i][0];

    / / Get the right value

    / / of the current round.

    int right = rounds[i][1];

    / / Get the contribution

    / / for the current round.

    int contribution = rounds[i][2];

    / / Since the user uses 1-based

    / / indexing, subtract 1 from left

    / / and right as the program uses

    / / 0-based indexing. That is, the

    / / investments in the array start

    / / from 0 and not 1.

    right = right - 1;

    int j=0;

    / / Run the loop to add the

    / / contribution to all the investments

    / / between left and right, both inclusive.

    for (j=left; j<=right; j++)

    {

    investments[j] + = contribution;

    }

    i++;

    }

    / / Traverse the investments array

    / / to find the maximum element.

    max = investments[0];

    for (i=1; i
    {

    if (investments[i]>max)

    {

    max = investments[i];

    }

    }

    / / Return the

    / / maximum investment.

    return max;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “github Portfolio Balances An investor opens a new account and wants to invest in a number of assets. Each asset begins with a balance of o, ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers