← All problemsSign in

Matrix Sum

We call an N × M matrix nice, if it satisfies both these conditions: - Each of its elements is either a 0 or a 1. - We define two cells of the matrix to be adjacent, if they share a side. All the cells containing a 1 should form a single connected component. More formally: You should be able to reach any cell containing a 1 from any other cell containing a 1 through a sequence of steps, where a

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start