Patterns: Interview Questions to Practice

Robin Kamboj
Sep 6, 2018 · 3 min read

Questions:

1. Triangle of numbers

Print the following pattern for the given number of rows.

Pattern for N = 3

    1
232
34543

Input format :Integer N (Total no. of rows)

Output format :Pattern in N lines

Sample Input :5

Sample Output :

    1
232
34543
4567654
567898765

2. Number Pattern

Print the following pattern

Pattern for N = 4

   1
23
345
4567

Input Format :N (Total no. of rows)

Output Format :Pattern in N lines

Sample Input :5

Sample Output :

    1
23
345
4567
56789

3. Number Pattern 5

Print the following pattern for n number of rows.

For eg. N = 5

1        1
12 21
123 321
1234 4321
1234554321

Sample Input 1 :4

Sample Output 1 :

1      1
12 21
123 321
12344321

4. Arrow Pattern

Print the following pattern for the given number of rows.

Assume N is always odd.

Note : There is space after every star.Pattern for N = 7

*
* *
* * *
* * * *
* * *
* *
*

Input format :Integer N (Total no. of rows)

Output format :Pattern in N lines

Sample Input :11

Sample Output :

*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*

5. Number Pattern

Print the following pattern

Pattern for N = 4

4 4 4 4 4 4 4 
4 3 3 3 3 3 4
4 3 2 2 2 3 4
4 3 2 1 2 3 4
4 3 2 2 2 3 4
4 3 3 3 3 3 4
4 4 4 4 4 4 4

Input Format :N (Total no. of rows)

Output Format :Pattern in N lines

Sample Input 1 :5

Sample Output 1 :

5 5 5 5 5 5 5 5 5 
5 4 4 4 4 4 4 4 5
5 4 3 3 3 3 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4 5
5 5 5 5 5 5 5 5 5

6. Print Pattern

Print the following pattern for the given number of rows.

Pattern for N = 5

1    2   3    4   5
11 12 13 14 15
21 22 23 24 25
16 17 18 19 20
6 7 8 9 10

Input format : N (Total no. of rows)

Output format : Pattern in N lines

Sample Input :4

Sample Output :

1  2  3  4
9 10 11 12
13 14 15 16
5 6 7 8

7. Print Pattern (Mountain Pattern)


8. Print Pattern (Staircase Pattern)


9. Print Pattern (Diamond Pattern)


10. Print Pattern (Triangles in a Box)

Robin Kamboj

Written by

Software Engineer by profession. Designer by force. Bibliophile by nature.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade