Problem Β· Prefix Sum

Growth in 2 Dimensions πŸ‚

Learn this problem
● MediumIxlFULLTIMEOA

Problem statement

Start with an infinite two dimensional grid filled with zeros, indexed from (1, 1) at the bottom left corner with coordinates increasing toward the top and right. Given a series of coordinates (r, c), where r is the ending row and c is the ending column, add 1 to each element in the range from (1, 1) to (r, c) inclusive. Once all coordinates are processed, determine how many cells contain the maximal value in the grid.

Function

countMax(upRight: String[]) β†’ int

Complete the function countMax in the editor.

countMax has the following parameter(s):

  1. String[] upRight: an array of strings made of two space-separated integers representing r and c respectively

Returns

int: the number of cells that contain the maximal value

Examples

Example 1

upRight = ["1 4", "2 3", "4 1"]return = 1
Example 1 illustration
The two space-separated integers within each string represent r and c respectively. The following diagrams show each iteration starting at zero. The maximal value in the grid is 3, and there is 1 occurrence at cell (1, 1).

Constraints

Unknown for now

More Ixl problems

drafts saved locally
public int countMax(String[] upRight) {
    // write your code here
}
upRight["1 4", "2 3", "4 1"]
expected1
checking account