Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Feature #4: Maximum Profit

Douglas Roncke answered on May 24, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Feature #10: Minimum Variation

  • Feature #4: Maximum Profit

    0
    Popularity 1/10 Helpfulness 1/10 Language abap
    Source: Grepper
    Tags: abap
    Link to this answer
    Share Copy Link
    Contributed on Jul 05 2023
    Douglas Roncke
    0 Answers  Avg Quality 2/10

    Closely Related Answers



    0

    The basic idea is to scan the entire array and at each position find the maximum sum of the sub-array ending there. This is achieved by keeping a currentMax for the current array index and a globalMax.

    Let’s see how we might implement this functionality:

    Initialize a currentMax and a globalMax and assign them the first value of the array.

    Traverse the array starting with the second element.

    For each element, check whether currentMax is less than zero:

    If it is less than zero, assign it the current element as its value

    Otherwise, add the current element in the currentMax

    Similarly, for each element check if globalMax is less than currentMax then assign globalMax equal to the value of currentMax

    The following illustration might clarify this process.

    Popularity 1/10 Helpfulness 1/10 Language scala
    Source: Grepper
    Tags: scala
    Link to this answer
    Share Copy Link
    Contributed on May 24 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.