AlgoInsight

DSA problem

Floyd's Triangle

EasyPattern PrintingPattern: Nested LoopsbeginnerFree

Given an integer N, print Floyd's Triangle - a right-angled triangle whose cells are filled with consecutive natural numbers starting from 1.

The shape is the same as a right-angled star triangle, but instead of stars you write the running counter: 1 on the first row, 2 and 3 on the second, 4 5 6 on the third, and so on. The counter lives outside both loops and increments with every number printed.

This teaches you about carrying state across iterations - a concept that appears everywhere from database cursors to stream processing.

Examples

Example 1
Input: N = 5
Output: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Explanation: A single counter increments across all cells; row i holds i consecutive numbers.

Constraints

3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.

patternnumbers

Browse all DSA problems