FastPrepEmployee With the Highest Salary

Employee With the Highest Salary

Mastercard logoMastercard● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

You are given two arrays of equal length:

  • names[i] is the name of the i-th employee.
  • salaries[i] is that employee's salary.

Return the name of the employee with the highest salary. If several employees share the highest salary, return the name that appears first in the input.

Function

highestSalaryName(names: String[], salaries: int[]) → String

Examples

Example 1

names = ["Ava","Ben","Chen"]salaries = [70000,92000,85000]return = "Ben"

Ben has the largest salary, 92000.

Example 2

names = ["Mina","Noah","Omar"]salaries = [50000,61000,61000]return = "Noah"

Noah and Omar tie for the highest salary, so return the earlier name.

Example 3

names = ["Zoe"]salaries = [0]return = "Zoe"

The only employee is the answer.

Constraints

  • 1 <= names.length = salaries.length <= 10^5.
  • names[i] is non-empty.
  • 0 <= salaries[i] <= 10^9.

More Mastercard problems

See Mastercard hiring insights
public String highestSalaryName(String[] names, int[] salaries) {
  // Write your code here.
}
names["Ava","Ben","Chen"]
salaries[70000,92000,85000]
expected"Ben"
Checking account…