Binary Triangle

Given a positive integer n, return a left-aligned binary triangle with n rows. Row i contains i digits separated by one space. The first digit is 1 when i is…

Given a positive integer n, return a left-aligned binary triangle with n rows. Row i contains i digits separated by one space. The first digit is 1 when i is odd and 0 when i is even; every following digit alternates. Do not add trailing spaces. Join adjacent rows with one newline character and do not add a trailing newline.

- 1 ≤ n ≤ 10 - n is always a positive integer. - Digits in every row strictly alternate between 0 and 1.

Example 1: input n = 4; output 1 0 1 1 0 1 0 1 0 1. Odd rows begin with 1, even rows begin with 0, and each row alternates.

Example 2: input n = 1; output 1. The first row contains the single digit 1.

Category: Pattern Programs. Topic: pattern-programs. Difficulty: Easy. Patterns: math.