Number Pattern: Floyd's Triangle Variant

Hard ⏱ 18 min 38% acceptance ★★★★★ 4.8
Write a function floyds_triangle(n) that returns the first n rows of Floyd's Triangle as a list of lists of integers, where the numbers 1, 2, 3, ... fill the triangle row by row left to right (row i, 1-indexed, has i numbers), continuing the count across rows rather than restarting each row.

Examples

Example 1
Input
floyds_triangle(4)
Output
[[1], [2, 3], [4, 5, 6], [7, 8, 9, 10]]
Explanation

Numbers increase continuously row by row.

Constraints

  • n is a positive integer.

Topics

Loopsnested loopspattern printing

Companies

IBMOracle

Hints

Hint 1

Keep a single running counter that increments across the entire structure, not per row.

Hint 2

Outer loop controls row length; inner loop fills that many numbers using the counter.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.