Problem · Array

Find Max Heart Rate Difference

Learn this problem
EasyGoogle logoGoogleINTERNOA
See Google hiring insights

Problem statement

A health monitoring device recorded N consecutive measurements. At the K-th measurement, the device recorded heart rate heartRate[K] and activity level activityLevel[K] (possible levels are "Low", "Normal", or "High").

Find the maximum difference between the highest and lowest heart rate values within the same activity level over a single period.

ᡣ • . • 𐭩 ✎𓆙Credit to 77

Function

findMaxHeartRateDifference(heartRate: int[], activityLevel: String[]) → int

Examples

Example 1

heartRate = [100, 87, 90, 90, 125]activityLevel = ["Normal", "Normal", "Normal", "High", "Low"]return = 13
Within the three periods of "Normal" activity level, the heart rate ranges from 87 to 100, with the maximum difference being 13.

Constraints

  • 1 <= heartRate.length == activityLevel.length <= 10^5
  • 1 <= heartRate[i] <= 300
  • activityLevel[i] is "Low", "Normal", or "High".

More Google problems

drafts saved locally
public int findMaxHeartRateDifference(int[] heartRate, String[] activityLevel) {
  // write your code here
}
heartRate[100, 87, 90, 90, 125]
activityLevel["Normal", "Normal", "Normal", "High", "Low"]
expected13
checking account