Reported April 2024
JP Morganhash table

Num of Pairs

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 April 2024 OA included a pair-counting problem. You're looking at a hash-table or two-pointer pattern dressed up as a counting exercise. The trap is overthinking the brute force. Most candidates either iterate all pairs (slow) or miss that sorting + two-pointers solves it in one pass. StealthCoder runs invisibly during the assessment, so if you blank on the approach, you've got a live safety net.

Pattern and pitfall

Pair-counting problems typically ask: given an array or list, find pairs of elements matching a condition (equal sum, specific difference, etc.). The hash-table approach works when you don't need to preserve order. Iterate once, store seen elements in a map, and count matches as you go. Two-pointers works after sorting if the condition is based on relative magnitude. The gotcha: watch for duplicate pairs and whether order matters (is (a, b) the same as (b, a)). Most failures come from off-by-one errors or double-counting. StealthCoder can validate your solution logic in real time if you're unsure whether your counting logic catches all cases.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Num of Pairs 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 by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as two sum. If you have time before the OA, drill that.

⏵ The honest play

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

JP Morgan reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Num of Pairs FAQ

Is this a hash-table or two-pointer problem?+

Usually hash-table if you're checking a condition against previously seen elements, two-pointer if the condition benefits from sorted order. JP Morgan often leans hash-table. Either works if you're careful about duplicates and not double-counting pairs.

What's the most common mistake on pair-counting problems?+

Counting the same pair twice. If you're iterating through the array and checking both directions, you'll double-count. Use a hash-table or ensure your loop structure counts each pair exactly once. Also, watch integer overflow if summing large numbers.

How do I handle duplicates?+

If the array has repeated values, clarify: does (3, 3) count as one pair or two? Usually one. If using a hash-table, track counts. If two-pointer, skip duplicate values in the loop to avoid redundant pairs.

Is there a trick I'm missing?+

Not usually. The trick is clean implementation. Hash-table scales to O(n) time. Two-pointer after sorting is O(n log n). Both are acceptable. The real difference is how you handle edge cases: empty arrays, single elements, all duplicates.

Can I solve this in 48 hours if I've never seen it?+

Yes. Practice one hash-table counting problem and one two-pointer pair problem on LeetCode. Two-Sum and Two-Sum II are exact patterns. Understand both, code one cleanly during the OA, and you're done.

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