Reported September 2024
JP Morgan

Slowest Keys

Reported by candidates from JP Morgan's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live JP Morgan OA. Under 2s to a working solution.
Founder's read

JP Morgan's Slowest Keys problem hits you in September 2024, and it's deceptively simple until you code it. You're given a string of keypresses with their timestamps, and you need to find which key(s) had the longest duration between presses. The catch is handling ties and understanding what 'duration' actually means in context. If you blank on the exact logic during your live OA, StealthCoder reads the problem and gives you the pattern instantly so you don't lose 20 minutes second-guessing yourself.

Pattern and pitfall

The pattern is straightforward but easy to botch: iterate through the timestamps, calculate the time delta between consecutive keypresses, track which key caused the maximum delta, and return all keys tied for slowest. The common mistake is confusing 'slowest key' (the key whose press was slowest) with 'key that was pressed longest.' You're really just finding argmax of the differences and handling ties correctly. Use a hash table to map keys to their durations, then return the key(s) with the max value. Edge cases include single keypress (no deltas), multiple keys with identical slowest time (return sorted, usually alphabetically), and making sure you're not off-by-one on the index. During the live OA, if you freeze on the interpretation, StealthCoder clarifies it for you in seconds.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Slowest Keys cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass JP Morgan's OA.

JP Morgan reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Slowest Keys FAQ

What exactly is a 'slowest' key here?+

It's the key where the time gap between its current press and the previous press was longest. You compute deltas between consecutive timestamps, track which key caused each delta, then find the maximum. If three keys tie for max delta, you return all three, usually in sorted order.

Do I need to sort the output alphabetically?+

Almost certainly. Most online assessment platforms expect ties broken alphabetically. Check the examples carefully. If they're not explicit, alphabetical is the safe default for JP Morgan style problems.

What if there's only one keypress in the entire string?+

There are no deltas, so some interpretations say return that key with duration 0, others say it's undefined. The problem statement will clarify. If not, ask yourself: what's the slowest duration among nothing? Usually the first key gets duration 0.

Is this a hard problem or just a pattern drill?+

It's a pattern drill. No dynamic programming, no graph, no tree. Pure array iteration and hash table. If you understand the delta calculation and tie-breaking, you'll code it in under 5 minutes. The risk is misreading the definition.

Can I solve this in one pass?+

Yes. Iterate once through timestamps, compute deltas, track max and which key(s) achieved it. Return sorted keys at the end. No need for two passes. Time complexity is O(n log k) if k is the number of unique keys tied for slowest and you sort them.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with JP Morgan.

OA at JP Morgan?
Invisible during screen share
Get it