JPMorgan Chase's HackerRank OA sits in the "moderately easy" tier among fintech firms—but two problems are usually paired: Distinct Digit Numbers (count integers in a range whose digits are all distinct) and First K-Winner Queue Tournament. Neither is LeetCode Hard, but JPM's hidden tests scale to 1e6 inputs—naïve brute force TLEs in some variants. This post gives full Python solutions, complexity proofs, and a bridge to the Leadership Principles behavioral round that follows.
JPMorgan OA Overview
| Dimension | Detail |
|---|---|
| Platform | HackerRank for Work |
| Duration | 60-75 minutes |
| Questions | 2-3 |
| Difficulty | LeetCode Easy ~ Medium |
| Target roles | NAMR SWE / AWM Tech / CIB Tech / Research Tech |
| Pass rate | ~35-45% |
Problem 1: Distinct Digit Numbers
Description
Given a range [n, m], count the integers in [n, m] whose decimal digits are all distinct.
Example:
n = 10, m = 25
Valid: {10, 12, 13, 14, …, 21, 23, 24, 25}
Invalid: {11, 22} (repeated digit)
Approach
Brute force: O((m-n) × log m)
Convert each number to a string and check len(set(s)) == len(s).
def count_distinct_brute(n: int, m: int) -> int:
count = 0
for num in range(n, m + 1):
s = str(num)
if len(set(s)) == len(s):
count += 1
return count
Range: passes for m - n ≤ 1e6. Some JPMorgan variants give 1e9 ranges—then digit DP is required.
Digit DP: O(D × 2^D)
Compute f(x) = number of distinct-digit integers in [0, x]; answer = f(m) - f(n-1).
from functools import lru_cache
def count_distinct(n: int, m: int) -> int:
def f(x: int) -> int:
if x < 0:
return 0
digits = [int(c) for c in str(x)]
D = len(digits)
@lru_cache(maxsize=None)
def dp(pos: int, mask: int, tight: bool, started: bool) -> int:
if pos == D:
return 1 if started else 0
limit = digits[pos] if tight else 9
total = 0
for d in range(0, limit + 1):
if started and (mask >> d) & 1:
continue
new_mask = mask | (1 << d) if (started or d > 0) else mask
total += dp(
pos + 1,
new_mask,
tight and (d == limit),
started or (d > 0),
)
return total
return dp(0, 0, True, False)
return f(m) - f(n - 1)
Time: O(D × 2^D × 10), D ≤ 10
Space: O(D × 2^D)
Practical strategy
JPMorgan's hidden tests usually keep
m ≤ 1e6, so brute force is enough for full marks. Best practice in your code:
- Add a sanity comment:
# fallback to digit DP if range > 1e7- Use
len(set(s)) == len(s)instead of an explicit loop- Handle
n < 0(JPMorgan expects 0)
Problem 2: First K-Winner in Queue Tournament
Description
Players with potentials[i] enter a queue. Each round:
- The two front players fight; the higher potential wins
- The loser goes to the back
- The winner stays in front and increments
win_streak - Return the first player to reach
kconsecutive wins
Example:
potentials = [3, 1, 4, 2, 5]
k = 3
# 3 vs 1 → 3 wins, streak=1, [3,4,2,5,1]
# 3 vs 4 → 4 wins, streak=1
# 4 vs 2 → 4 wins, streak=2
# 4 vs 5 → 5 wins, streak=1
# 5 vs 1 → 5 wins, streak=2
# 5 vs 3 → 5 wins, streak=3 → return 5
Approach
Naïve deque simulation O(n × k) worst case
from collections import deque
def first_k_winner_naive(potentials, k):
q = deque(potentials)
current = q.popleft()
streak = 0
while streak < k:
challenger = q.popleft()
if current > challenger:
streak += 1
q.append(challenger)
else:
q.append(current)
current = challenger
streak = 1
return current
For k=n × n, this TLEs.
Optimal: "max always wins" O(n)
Insight: the array's max necessarily wins within the first n rounds. If k ≥ n, the answer is max(potentials). Otherwise, naïve simulation runs at most n + k iterations.
from collections import deque
from typing import List
def first_k_winner(potentials: List[int], k: int) -> int:
if k >= len(potentials):
return max(potentials)
q = deque(potentials)
current = q.popleft()
streak = 0
while streak < k:
challenger = q.popleft()
if current > challenger:
streak += 1
q.append(challenger)
else:
q.append(current)
current = challenger
streak = 1
return current
Time: O(n + k), with k ≤ n after the early return
Space: O(n)
Hidden-case defenses
| Input | Expected |
|---|---|
potentials = [1], k = 1 |
1 (single player wins by default) |
potentials = [5, 5, 5], k = 2 |
The earlier-indexed player wins on ties |
k = 0 |
The front of the queue |
k > n^2 |
max(potentials) |
After the OA: Behavioral Round + Leadership Principles
After clearing the OA, HR usually contacts you within 1-2 weeks for HireVue video or a recruiter phone screen. Both heavily emphasize JPMorgan's Leadership Principles:
| Principle | Common Question |
|---|---|
| Customer Centricity | "Tell me about a time you balanced a client request with internal constraints" |
| Drive Innovation | "Describe a project where you challenged the status quo" |
| Set the Standard for Integrity | "Tell me about an ethical decision you made" |
| Foster Inclusion | "Describe a cross-cultural collaboration" |
| Embrace Change | "Talk about adapting to ambiguous requirements" |
STAR template: Situation 10s → Task 10s → Action 40s → Result 10s.
FAQ
What's the JPMorgan OA pass rate?
Roughly 35-45%. NAMR SWE skews lower (high volume); CIB Tech skews higher (fewer applicants with finance background). You must complete both problems with green hidden tests—finishing only one almost always fails.
How long until I get OA results?
Average 7-14 business days. AWM is slower (up to 3 weeks). Tech functions usually reply within a week.
Do I need digit DP for Distinct Digit Numbers?
Not usually. ~95% of JPMorgan hidden tests stay under 1e6. Brute force gets full marks. Drop a comment like "if range > 1e7 use digit DP" to signal awareness.
Does Queue Tournament have a LeetCode equivalent?
Closest match: LeetCode 1535. Find the Winner of an Array Game. JPMorgan's variant relaxes the constraint—k > n is allowed, so add the k >= len(potentials) early return.
Best language for JPMorgan OA?
Python > Java > C++ in terms of pass density. HackerRank's Python is 5-10× slower than C++, but JPMorgan's 1e6 data still fits comfortably—and Python's readability earns rubric points.
Preparing for the JPMorgan OA?
oavoservice supports JPMorgan / Goldman Sachs / Morgan Stanley / BlackRock OA prep end-to-end. We map the differences across NAMR SWE, AWM Tech, and CIB Tech OA tracks and tailor your Leadership Principles STAR templates to your target LOB.
Add WeChat Coding0201 to book JPMorgan OA coaching.
#JPMorgan #JPMorganOA #HackerRank #FinanceTech #SWE #OARealQuestions
Contact
Email: [email protected]
Telegram: @OAVOProxy