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 challengesBalanced Tower Builder

Gamified challenge · Divide and conquer

Balanced Tower Builder

blocks holds the numbers of your blocks in increasing order, all different. Build a tower that is a binary search tree: every block's left side holds only smaller numbers and its right side only bigger ones. Use every block exactly once.

The tower must be balanced: at every block, the left and right sides' heights differ by at most one floor. Write build(blocks) that returns the top block as a TreeNode (null / None for no blocks). Any balanced tower with the right blocks passes.

For [1, 2, 3, 4, 5], [3, 1, 4, null, 2, null, 5] (3 on top, 1 and 4 below it, then 2 and 5) is one right answer, and so is [3, 2, 5, 1, null, 4].

Sign in to play Balanced Tower Builder

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