New update is available. Click here to update.
sidenav-btnClose
Topic list
Number Pattern
EASY
15 mins
7 upvotes
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Sorting
-
Binary Search
-
Linked List
-
Stacks & Queues
-
Trees
-
Graph
-
Dynamic Programming
-
Greedy
-
Tries
-
Arrays
-
Binary Search Trees
-
Heap
-
Bit Manipulation
-

Number Pattern

Contributed by
Aditya Agarwal
Easy
Avg time to solve 15 mins
Success Rate 85 %
Share
7 upvotes

Problem Statement

Ninja wants to build a number pattern.

Example For ‘N’ = 4 

Pattern:

4444
3444
2344
1234

Your task is to make a program that prints a similar pattern for a given 'N'.

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1:
2
5
2
Sample Output 1:
55555
45555
34555
23455
12345
22
12
Explanation of Sample Input 1:
Test case 1:

In the first test case, as ‘N’ is equal to ‘5’, We will have to print five lines. We have a print a square-like pattern where the upper right triangle along with the main diagonal will be filled with the input number and the lower-left triangle will be a triangle wherein each row, number of elements increases from ‘1’ to ‘N’ - 1;

Test case 2:

In the second test case, as ‘N’ is equal to ‘2’, We will have to print two lines.
Sample Input 2:
2
1
4
Sample Output 2:
1
4444
3444
2344
1234
Explanation of Sample Input 2:
Test case 1:
As ‘N’ is equal to ‘1’, we just need to print one line i.e 1. 
Reset Code
Full screen
copy-code
Console