Loading the journal
Loading the journal
Index-based Traversal / ConditionalsSolved Oct 23, 2025
Problem
Given a square matrix of size N × N, find the sum of its lower triangle elements. The lower triangle includes the main diagonal and all elements below it.
Index Condition: Elements ar[i][j] are in the lower triangle if and only if i ≥ j.
Input: 3 5 9 -2 -3 4 1 2 6 1
Output: 15
Explanation: Sum of elements (5, -3, 4, 2, 6, 1) = 15.
Reading the solution first feels like progress, but it makes the next similar problem — and the interview version — much harder, because you skipped the part where you figure it out. Give it an honest 20–30 minutes. Stuck? Re-read the pattern, watch the concept video, or try the brute force first.
Hidden: approach · solution code