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 challengesLazy Paint Fence

Gamified challenge · Segment trees

Lazy Paint Fence

A fence has n planks numbered 1 to n, all bare. ops is a list of orders, carried out in order: "add l r c" adds c coats to every plank from l to r (inclusive), and "sum l r" asks for the total coats on planks l to r. Always 1 ≤ l ≤ r ≤ n and c ≥ 1.

Write paint(n, ops) that returns the answers to the sum orders, in order (an empty list if there are none). For n = 6 and ["add 2 5 3", "sum 1 4", "add 1 6 1", "sum 4 6", "sum 1 1"] the answer is [9, 9, 1].

Walking the planks works for small fences; the lazy segment tree answers every order in O(log n) by leaving a pending tag on any node whose whole range is painted.

Sign in to play Lazy Paint Fence

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