Tap here to switch tabs
Problem
Submissions

Problem: Slowest Key

Try to solve the Slowest Key problem.

Statement

A keypad was tested by typing a sequence of nn keypresses, resulting in a string keysPressed of length nn.

You are given a strictly increasing integer array releaseTimes of length nn, where releaseTimes[i] represents the exact time the key at index ii was released. The key at index 00 was pressed at time 00, and each subsequent key at index ii was pressed immediately after the key at index i−1i - 1 was released.

The duration of the keypress at index 00 is releaseTimes[0], and the duration of any keypress at index ii where 1≤i<n1 \leq i < n is releaseTimes[i] −- releaseTimes[i - 1].

Return the key that had the longest duration. If multiple keys have the same longest duration, return the lexicographically largest character among them.

Constraints:

  • releaseTimes.length ==n== n

  • keysPressed.length ==n== n

  • 2≤n≤10002 \leq n \leq 1000

  • 1≤1 \leq releaseTimes[i] ≤109\leq 10^9

  • releaseTimes[i] << releaseTimes[i + 1] for all 0≤i<n−10 \leq i < n - 1

  • keysPressed contains only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Slowest Key

Try to solve the Slowest Key problem.

Statement

A keypad was tested by typing a sequence of nn keypresses, resulting in a string keysPressed of length nn.

You are given a strictly increasing integer array releaseTimes of length nn, where releaseTimes[i] represents the exact time the key at index ii was released. The key at index 00 was pressed at time 00, and each subsequent key at index ii was pressed immediately after the key at index i−1i - 1 was released.

The duration of the keypress at index 00 is releaseTimes[0], and the duration of any keypress at index ii where 1≤i<n1 \leq i < n is releaseTimes[i] −- releaseTimes[i - 1].

Return the key that had the longest duration. If multiple keys have the same longest duration, return the lexicographically largest character among them.

Constraints:

  • releaseTimes.length ==n== n

  • keysPressed.length ==n== n

  • 2≤n≤10002 \leq n \leq 1000

  • 1≤1 \leq releaseTimes[i] ≤109\leq 10^9

  • releaseTimes[i] << releaseTimes[i + 1] for all 0≤i<n−10 \leq i < n - 1

  • keysPressed contains only lowercase English letters.