FastPrepFilter by Threshold and Return Name with Max Score

Filter by Threshold and Return Name with Max Score

Upstart logoUpstart● EasyFULLTIMEOA
Learn

Problem statement

Complete the function below. The function receives the full standard input as a single string and must return the exact standard output lines for the described problem.

Problem Given records records = [(name, score), ...] and an integer threshold:

Filter out all records with score > threshold (keep score <= threshold).

Among the remaining records, find the record with the maximum score and output its name.

Constraints: At least one record satisfies score <= threshold.

name is a no-space string, score is an integer.

Input:

Line 1: integer n

Line 2: integer threshold

Next n lines: name score

Output:

One line: the name with the maximum score among those <= threshold.

Example: Input:

4

80

alice 50

bob 90

cindy 80

dave 70

Output:

cindy

Example Input

4

80

alice 50

bob 90

cindy 80

dave 70

Output

cindy

Function

solveFilterThresholdMaxScore(input: String) → String[]

Complete solveFilterThresholdMaxScore. It has one parameter, String input, containing the full stdin payload. Return the stdout payload as an array of lines, without trailing newline characters.

Examples

Example 1

input = "4\n80\nalice 50\nbob 90\ncindy 80\ndave 70"return = ["cindy"]

The returned string array must match the expected standard output lines for the sample input.

Constraints

  • Use the limits and requirements stated in the prompt.

More Upstart problems

See Upstart hiring insights
public String[] solveFilterThresholdMaxScore(String input) {
    // write your code here
}
input"4\n80\nalice 50\nbob 90\ncindy 80\ndave 70"
expected["cindy"]
Checking account…