Advanced Pattern Problems With Solutions For Interviews
Advanced Pattern Problems With Solutions For Interviews
AAR Blog
Advance Pattern
Problems with Solution
For Interviews
Follow me on Instagram
Follow me on X
https://blog.aakashdev.in/blog/advance-pattern-problems 1/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Table of Contents
1. Right-Angled Triangle
2. Inverted Right-Angled Triangle
3. Pyramid Pattern
4. Diamond Pattern
5. Hollow Rectangle
6. Number Pyramid
7. Pascal's Triangle
8. Fibonacci Triangle
9. Half Pyramid with Numbers
10. Inverted Half Pyramid with Numbers
11. Floyd's Triangle
12. Butterfly Pattern
13. Hollow Diamond Pattern
14. Zigzag Pattern
15. Hollow Square Pattern
16. Left-Aligned Number Triangle
17. Right-Aligned Star Triangle
18. Alternating Rectangle Pattern (0 and 1)
19. Hourglass Pattern
20. Hollow Pyramid Pattern
21. X Pattern
22. Palindromic Number Pyramid
https://blog.aakashdev.in/blog/advance-pattern-problems 2/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
*
**
https://blog.aakashdev.in/blog/advance-pattern-problems 3/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
***
****
*****
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}
*
**
***
****
*****
https://blog.aakashdev.in/blog/advance-pattern-problems 4/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
*****
****
***
**
*
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}
https://blog.aakashdev.in/blog/advance-pattern-problems 5/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
*****
****
***
**
*
Example:
For `n = 5`:
*
***
*****
*******
*********
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
https://blog.aakashdev.in/blog/advance-pattern-problems 6/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
*
***
*****
*******
*********
Example:
For `n = 5`:
*
***
*****
*******
*********
*******
https://blog.aakashdev.in/blog/advance-pattern-problems 7/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
*****
***
*
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
// Upper half
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int k = 1; k <= 2 * i - 1; ++k) {
cout << "*";
}
cout << endl;
}
// Lower half
for (int i = n - 1; i >= 1; --i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int k = 1; k <= 2 * i - 1; ++k) {
cout << "*";
}
cout << endl;
}
https://blog.aakashdev.in/blog/advance-pattern-problems 8/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
return 0;
}
*
***
*****
*******
*********
*******
*****
***
*
Example:
For `rows = 4` and `columns = 5`:
*****
* *
* *
*****
Solution:
https://blog.aakashdev.in/blog/advance-pattern-problems 9/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
#include <iostream>
using namespace std;
int main() {
int rows, columns;
cout << "Enter number of rows and columns: ";
cin >> rows >> columns;
*****
* *
* *
*****
https://blog.aakashdev.in/blog/advance-pattern-problems 10/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 11/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Example:
For `n = 5`:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 12/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Example:
For `n = 5`:
https://blog.aakashdev.in/blog/advance-pattern-problems 13/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
1 1
1 2 3
5 8 13 21
34 55 89 144 233
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
int a = 1, b = 1, c;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cout << a << " ";
c = a + b;
a = b;
b = c;
}
cout << endl;
}
return 0;
}
1
1 1
https://blog.aakashdev.in/blog/advance-pattern-problems 14/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1 2 3
5 8 13 21
34 55 89 144 233
Example:
For `n = 5`:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cout << j << " ";
}
cout << endl;
https://blog.aakashdev.in/blog/advance-pattern-problems 15/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
}
return 0;
}
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Example:
For `n = 5`:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Solution:
#include <iostream>
using namespace std;
https://blog.aakashdev.in/blog/advance-pattern-problems 16/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
cout << j << " ";
}
cout << endl;
}
return 0;
}
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Example:
For `n = 5`:
1
2 3
https://blog.aakashdev.in/blog/advance-pattern-problems 17/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
4 5 6
7 8 9 10
11 12 13 14 15
Solution:
#include <iostream>
using namespace std;
int main() {
int n, num = 1;
cout << "Enter number of rows: ";
cin >> n;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cout << num << " ";
++num;
}
cout << endl;
}
return 0;
}
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
https://blog.aakashdev.in/blog/advance-pattern-problems 18/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 4`:
* *
** **
*** ***
********
********
*** ***
** **
* *
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
// Upper half
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= i; ++j) {
cout << "*";
}
for (int j = 1; j <= 2 * (n - i); ++j) {
cout << " ";
}
for (int j = 1; j <= i; ++j) {
https://blog.aakashdev.in/blog/advance-pattern-problems 19/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
// Lower half
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
cout << "*";
}
for (int j = 1; j <= 2 * (n - i); ++j) {
cout << " ";
}
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}
* *
** **
*** ***
********
********
*** ***
** **
* *
https://blog.aakashdev.in/blog/advance-pattern-problems 20/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
*
* *
* *
* *
* *
* *
* *
* *
*
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
// Upper half
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
cout << "*";
https://blog.aakashdev.in/blog/advance-pattern-problems 21/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
if (i > 1) {
for (int j = 1; j <= 2 * (i - 1) - 1; ++j) {
cout << " ";
}
cout << "*";
}
cout << endl;
}
// Lower half
for (int i = n - 1; i >= 1; --i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
cout << "*";
if (i > 1) {
for (int j = 1; j <= 2 * (i - 1) - 1; ++j) {
cout << " ";
}
cout << "*";
}
cout << endl;
}
return 0;
}
*
* *
* *
* *
* *
* *
* *
https://blog.aakashdev.in/blog/advance-pattern-problems 22/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
* *
*
Example:
For `n = 3` and `columns = 9`:
* *
* * * *
* * * *
Solution:
#include <iostream>
using namespace std;
int main() {
int n, columns;
cout << "Enter number of levels and columns: ";
cin >> n >> columns;
https://blog.aakashdev.in/blog/advance-pattern-problems 23/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
}
cout << endl;
}
return 0;
}
* *
* * * *
* * * *
Example:
For `n = 5`:
*****
* *
* *
* *
*****
Solution:
https://blog.aakashdev.in/blog/advance-pattern-problems 24/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter side length: ";
cin >> n;
*****
* *
* *
* *
*****
https://blog.aakashdev.in/blog/advance-pattern-problems 25/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
1
22
333
4444
55555
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 26/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
22
333
4444
55555
Example:
For `n = 5`:
*
**
***
****
*****
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 27/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
*
**
***
****
*****
Example:
For `n = 4` and `m = 5`:
01010
10101
https://blog.aakashdev.in/blog/advance-pattern-problems 28/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
01010
10101
Solution:
#include <iostream>
using namespace std;
int main() {
int n, m;
cout << "Enter number of rows and columns: ";
cin >> n >> m;
01010
10101
01010
10101
https://blog.aakashdev.in/blog/advance-pattern-problems 29/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
*********
*******
*****
***
*
***
*****
*******
*********
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter the number of rows for the top half: ";
cin >> n;
// Upper half
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
https://blog.aakashdev.in/blog/advance-pattern-problems 30/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
}
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "*";
}
cout << endl;
}
// Lower half
for (int i = 2; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int j = 1; j <= 2 * i - 1; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}
*********
*******
*****
***
*
***
*****
*******
*********
https://blog.aakashdev.in/blog/advance-pattern-problems 31/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
*
* *
* *
* *
*********
Example:
For `n = 5`:
* *
* *
*
* *
* *
Solution:
https://blog.aakashdev.in/blog/advance-pattern-problems 32/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter an odd number of rows (for an X pattern): ";
cin >> n;
* *
* *
*
* *
* *
https://blog.aakashdev.in/blog/advance-pattern-problems 33/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
Example:
For `n = 5`:
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 34/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
return 0;
}
1
2 1 2
3 2 1 2 3
4 3 2 1 2 3 4
5 4 3 2 1 2 3 4 5
Example:
For `n = 5`:
1
1 2
1 3
1 4
1 2 3 4 5
1 4
1 3
1 2
1
Solution:
https://blog.aakashdev.in/blog/advance-pattern-problems 35/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
// Upper half
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
cout << "1";
for (int j = 1; j <= 2 * (i - 1) - 1; ++j) {
cout << " ";
}
if (i != 1) {
cout << i;
}
cout << endl;
}
// Lower half
for (int i = n - 1; i >= 1; --i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
cout << "1";
for (int j = 1; j <= 2 * (i - 1) - 1; ++j) {
cout << " ";
}
if (i != 1) {
cout << i;
}
cout << endl;
https://blog.aakashdev.in/blog/advance-pattern-problems 36/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
}
return 0;
}
1
1 2
1 3
1 4
1 2 3 4 5
1 4
1 3
1 2
1
Example:
For `n = 5`:
*****
*****
*****
*****
*****
Solution:
https://blog.aakashdev.in/blog/advance-pattern-problems 37/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
*****
*****
*****
*****
*****
Example:
For `n = 5`:
*****
* *
* *
* *
*****
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 39/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
*****
* *
* *
* *
*****
Example:
For `n = 5`:
*********
* *
* *
* *
*
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 40/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
*********
* *
* *
* *
*
Example:
For `n = 4`:
https://blog.aakashdev.in/blog/advance-pattern-problems 41/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
2 3
4 5 6
7 8 9 10
4 5 6
2 3
1
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
int num = 1;
// Upper half
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int j = 1; j <= i; ++j) {
cout << num++ << " ";
}
cout << endl;
}
// Lower half
num -= n;
for (int i = n - 1; i >= 1; --i) {
for (int j = 1; j <= n - i; ++j) {
https://blog.aakashdev.in/blog/advance-pattern-problems 42/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
return 0;
}
1
2 3
4 5 6
7 8 9 10
4 5 6
2 3
1
Example:
For `n = 5`:
https://blog.aakashdev.in/blog/advance-pattern-problems 43/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 44/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
Example:
For `n = 3`:
* * *
* * * * * *
* * * *
Solution:
#include <iostream>
using namespace std;
int main() {
int n = 3; // Rows fixed
int cols = 9; // Width
https://blog.aakashdev.in/blog/advance-pattern-problems 45/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
} else {
cout << " ";
}
}
cout << endl;
}
return 0;
}
* * *
* * * * * *
* * * *
Example:
For `n = 5`:
* * * * *
* * * *
* * *
* * * *
* * * * *
Solution:
https://blog.aakashdev.in/blog/advance-pattern-problems 46/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter side length: ";
cin >> n;
* * * * *
* * * *
* * *
* * * *
* * * * *
Example:
For `n = 4`:
1
2 3
4 5 6
7 8 9 10
Solution:
#include <iostream>
using namespace std;
int main() {
int n, num = 1;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 48/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
1
2 3
4 5 6
7 8 9 10
Example:
For `n = 4`:
*
***
*****
*******
*****
***
*
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
https://blog.aakashdev.in/blog/advance-pattern-problems 49/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
cout << "Enter the number of rows for the upper half: ";
cin >> n;
// Upper half
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int k = 1; k <= 2 * i - 1; ++k) {
cout << "*";
}
cout << endl;
}
// Lower half
for (int i = n - 1; i >= 1; --i) {
for (int j = 1; j <= n - i; ++j) {
cout << " ";
}
for (int k = 1; k <= 2 * i - 1; ++k) {
cout << "*";
}
cout << endl;
}
return 0;
}
*
***
*****
*******
*****
https://blog.aakashdev.in/blog/advance-pattern-problems 50/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
***
*
Example:
For `n = 4`:
* *
** **
*** ***
********
********
*** ***
** **
* *
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
// Upper half
for (int i = 1; i <= n; ++i) {
https://blog.aakashdev.in/blog/advance-pattern-problems 51/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
// Lower half
for (int i = n; i >= 1; --i) {
for (int j = 1; j <= i; ++j) {
cout << "*";
}
for (int j = 1; j <= 2 * (n - i); ++j) {
cout << " ";
}
for (int j = 1; j <= i; ++j) {
cout << "*";
}
cout << endl;
}
return 0;
}
* *
** **
*** ***
********
https://blog.aakashdev.in/blog/advance-pattern-problems 52/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
********
*** ***
** **
* *
Example:
For `n = 5`:
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Solution:
#include <iostream>
using namespace std;
int main() {
int n;
cout << "Enter number of rows: ";
cin >> n;
https://blog.aakashdev.in/blog/advance-pattern-problems 53/54
8/20/25, 7:32 PM Advanced Pattern Problems with Solutions for Interviews
}
for (int j = 1; j <= i; ++j) {
cout << j << " ";
}
cout << endl;
}
return 0;
}
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
← Back to Home
https://blog.aakashdev.in/blog/advance-pattern-problems 54/54