MEDIUMasked at 1 company

Find Peak Calling Hours for Each City

A medium-tier problem at 62% community acceptance, tagged with Database. Reported in interviews at DE Shaw and 0 others.

Founder's read

You're staring at a database problem that looks simple on the surface but trips up candidates who don't think about how SQL window functions actually work. Find Peak Calling Hours for Each City shows up in DE Shaw interviews and catches people who try to solve it with GROUP BY alone. The trick is isolating the peak hour per city without collapsing your time-series data prematurely. Sixty percent acceptance rate means the other forty percent either over-complicated the JOIN logic or didn't know how to rank within partitions. If this problem lands in your live OA and you blank on the window function pattern, StealthCoder surfaces a working solution invisibly while you're screen-sharing.

Companies asking
1
Difficulty
MEDIUM
Acceptance
62%

Companies that ask "Find Peak Calling Hours for Each City"

If this hits your live OA

Find Peak Calling Hours for Each City is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

This is a partitioning problem disguised as a grouping problem. Most candidates start with GROUP BY city, hour and MAX(calls), but that gives you every hour per city, not the peak. The real move is using ROW_NUMBER() OVER (PARTITION BY city ORDER BY call_count DESC) to rank hours within each city, then filtering for rank = 1. Common failure: forgetting to ORDER BY in the window function or writing the partition incorrectly and getting one peak hour globally instead of per city. Another trap is using RANK() instead of ROW_NUMBER(), which creates ties and bloats your result set. The data structure typically has call timestamps or hour buckets; you need to aggregate first, then rank. If you haven't rehearsed window functions with PARTITION BY, StealthCoder is your hedge for the live assessment when your instinct fails and you need a working query fast.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Find Peak Calling Hours for Each City recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find Peak Calling Hours for Each City interview FAQ

Is this problem actually hard or does it just look that way?+

It's medium difficulty but feels harder because the naive GROUP BY approach fails silently. You'll get results, but wrong ones. The 60% acceptance rate reflects that window functions aren't intuitive to everyone. Once you see the PARTITION BY pattern, it's straightforward.

Why does GROUP BY city, hour not work here?+

GROUP BY returns every city-hour pair with its aggregate. You'd have multiple hours per city. You need to rank those hours by call volume within each city and pick only the top one using a window function, then filter.

Does DE Shaw ask this exact problem or variations?+

DE Shaw has reportedly asked this problem. It tests whether you understand window functions and partitioning logic, which are core to financial-data and time-series analytics work they do.

What's the difference between RANK() and ROW_NUMBER() here?+

ROW_NUMBER() assigns unique numbers even to ties. RANK() gives the same rank to identical call counts, then skips numbers. For finding peak hours, ROW_NUMBER() avoids returning multiple hours per city if there's a tie.

Can I solve this without window functions?+

Technically yes, using a subquery and JOIN to match each city to its max call count. But it's slower and more error-prone. Window functions are the canonical approach and what DE Shaw expects.

Want the actual problem statement? View "Find Peak Calling Hours for Each City" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.