GamifiedGamified challengesPracticeRaceLeaderboardPricing

Learn data structures by watching them move, then doing it yourself. Press M anytime to toggle sound.

A product of Amypo Technologies, Coimbatore.

Learn

  • All topics
  • Learning path
  • How it works
  • About dotprep

Practice

  • Practice arena
  • Daily challenge
  • Gamified challenges
  • Race mode
  • Leaderboard

Interview prep

  • Java interview
  • Coding questions
  • Company questions
  • System design
  • Jobs & careers

You

  • Dashboard
  • Settings
  • Pricing
  • Create account

© 2026 dotprep

Content last updated 20 November 2026

GamifiedGamified challengesPracticeRaceLeaderboardPricing
Log inStart free
Gamified challengesNearest Taxis

Gamified challenge · Max-heap of size k

Nearest Taxis

You are at (0, 0). taxis[i] = [x, y] is where taxi i is; no two taxis share a spot. A taxi's distance is the straight-line distance √(x² + y²), so comparing x² + y² is enough.

Write kClosest(taxis, k) (Python k_closest(taxis, k)) returning the k taxis nearest to you as [x, y] pairs, in any order. k is between 0 and the number of taxis. If several taxis tie at the cut-off distance, any of them may be returned.

Example: [[3, 3], [5, -1], [-2, 4]] with k = 2 → `[[3, 3], [-2, 4]]` (squared distances 18 and 20; the third is 26).

Sign in to play Nearest Taxis

This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.

Sign in with Google

or log in with email · create an account