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 137/Double Trouble
PrevNext
CodeChefCodeChef
4 Star
Starters 137

Double Trouble

GreedyArraySuffix ArrayPrefix SumMath
Loading...
Solve on CodeChef

Problem Statement

Official algorithmic problem description and constraints.

Open on CodeChef

Alice has π‘ magical balls placed on the π‘₯-axis. The π‘–-th ball is initially at position π‘‹π‘–​ and has a power of π‘ƒπ‘–​.

It is guaranteed that π‘‹π‘–<𝑋𝑖+1​ for 1≀𝑖<𝑁.

Initially, none of the balls are activated.

Alice can do the following at most twice:

  • Choose an index i (1≀𝑖≀𝑁) such that ball π‘– is not activated.
  • Activate ball π‘–, and choose a direction for it (either right or left).

When ball π‘– is activated in a certain direction, the following process takes place:

  • The ball will move π‘ƒπ‘– units in the chosen direction.
  • If, while moving, it strikes another ball π‘—, ball π‘– will immediately disappear. Then,
  • If ball j was previously activated, nothing happens, and the process immediately ends.
  • Otherwise, ball j activates in the same direction as ball i (that is, if ball i was moving left, ball j will move left too).
  • Note that the power of ball j doesn't change, and remains π‘ƒπ‘—.
  • If it never strikes another ball, it simply stops after moving a distance of π‘ƒπ‘– units.
  • In this case, the ball does not disappear.

Using at most two moves, is it possible for Alice to activate every ball?

Note that Alice can make her second move only after the entire process from the first move has completed.

Solutions & Walkthrough

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

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