HackerRank – Staircase (Java)

HackerRank – Staircase (Java)

Description

https://www.hackerrank.com/challenges/staircase

Consider a staircase of size n = 4:

Observe that its base and height are both equal to n, and the image is drawn using # symbols and spaces. The last line is not preceded by any spaces.

Write a program that prints a staircase of size n.

Input Format

A single integer, , denoting the size of the staircase.

Output Format

Print a staircase of size using # symbols and spaces.

Note: The last line must have 0 spaces in it.

Sample Input

Sample Output

Explanation

The staircase is right-aligned, composed of # symbols and spaces, and has a height and width of n = 6.

Explanation

The staircase is actually printed on a 2D array.

If (row index + column index) > n, print “#”; otherwise, print ” “.

Java Solution

Leave a Reply

Your email address will not be published. Required fields are marked *