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 challengesCommon Ancestor Hunt

Gamified challenge · Recursion

Common Ancestor Hunt

The family is a binary tree given as tree (a TreeNode root; examples are in level order with null for a missing child). Every relative has a different number, and the numbers a and b are both in the tree.

Write lca(tree, a, b) that returns the number of their nearest shared ancestor: the lowest person whose descendants include both a and b. A person counts as their own ancestor, so if a is above b the answer is a, and if a == b it is a.

In [3, 5, 1, 6, 2, 0, 8, null, null, 7, 4], lca(tree, 5, 1) is 3, lca(tree, 6, 4) is 5, and lca(tree, 5, 4) is 5.

Sign in to play Common Ancestor Hunt

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