Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew 🚀
Contest SolutionsPractice
Practice Sheets
MasterclassesLive 👨🏻‍💻

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
© 2026coding75•crackDSA™•Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021•Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/CodeChef/Starters 146/Bouncing Ball
PrevNext
CodeChefCodeChef
4 Star
Starters 146

Bouncing Ball

Prefix SumMathArray
Loading...
Solve on CodeChef

Problem Statement

Official algorithmic problem description and constraints.

Open on CodeChef

You are given an array A of length N, where each element represents either empty ground (Ai=0) or a wall (a positive integer indicating the height of the wall).


You can place a ball on any empty ground (that is, choose an index i with Ai=0) and push it either to the right or to the left.

When the ball hits a wall, it decreases the height of the wall it hit by 1, and then bounces back in the opposite direction. If the wall's height reaches 0


0, it becomes empty ground.

The ball continues to move until it goes out of bounds.

Determine the number of ways to place and push the ball so that all walls are destroyed. Two ways are considered different if either the starting index of the ball or the direction of the push is different.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Starters 146
Previous ProblemNext Problem