0% found this document useful (0 votes)
17 views12 pages

Top 50 Coding Patterns Explained

The document presents a collection of 50 pattern-based coding questions, primarily focused on star patterns, number patterns, and alphabet patterns. Each question includes a brief description and pseudocode for implementation. The patterns range from simple shapes like squares and triangles to more complex forms like diamonds and spirals.

Uploaded by

Yuvi Arvind Ram
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views12 pages

Top 50 Coding Patterns Explained

The document presents a collection of 50 pattern-based coding questions, primarily focused on star patterns, number patterns, and alphabet patterns. Each question includes a brief description and pseudocode for implementation. The patterns range from simple shapes like squares and triangles to more complex forms like diamonds and spirals.

Uploaded by

Yuvi Arvind Ram
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CODING / DSA

By Abhishek Rathor

Instagram: code.abhii07 (SYNTAX ERROR)

✅ Top 50 Pattern-Based Coding Questions

1. Square Star Pattern


{
// loop rows
for i = 1 to n
{
// loop columns
for j = 1 to n
print "*"
}
}

2. Right Triangle Star Pattern


{
// loop rows
for i = 1 to n
{
// print stars equal to row
for j = 1 to i
print "*"
}
}

3. Inverted Right Triangle


{
// loop rows
for i = n to 1
{
// print stars
for j = 1 to i
print "*"
}
}

4. Left Triangle Pattern


{
for i = 1 to n
{
// print spaces
for s = 1 to n-i
print " "

// print stars
for j = 1 to i
print "*"
}
}

5. Pyramid Star Pattern


{
for i = 1 to n
{
for s = 1 to n-i
print " "

for j = 1 to 2*i-1
print "*"
}
}

6. Inverted Pyramid
{
for i = n to 1
{
for s = 1 to n-i
print " "

for j = 1 to 2*i-1
print "*"
}
}

7. Diamond Pattern
{
// upper pyramid
print pyramid

// lower inverted pyramid


print inverted pyramid
}

8. Hollow Square
{
for i = 1 to n
{
for j = 1 to n
{
if i==1 or i==n or j==1 or j==n
print "*"
else
print " "
}
}
}

9. Hollow Pyramid
{
for i = 1 to n
{
for j = 1 to 2*i-1
{
if j==1 or j==2*i-1 or i==n
print "*"
else
print " "
}
}
}

10. Number Triangle


{
for i = 1 to n
{
for j = 1 to i
print j
}
}

11. Same Number Triangle


{
for i = 1 to n
{
for j = 1 to i
print i
}
}

12. Floyd’s Triangle


{
num = 1

for i = 1 to n
{
for j = 1 to i
{
print num
num++
}
}
}

13. Binary Triangle


{
for i = 1 to n
{
for j = 1 to i
{
if (i+j) % 2 == 0
print 1
else
print 0
}
}
}

14. Alphabet Triangle


{
for i = 1 to n
{
ch = 'A'

for j = 1 to i
{
print ch
ch++
}
}
}

15. Same Alphabet Triangle


{
for i = 1 to n
{
for j = 1 to i
print character(i)
}
}

16. Reverse Number Triangle


{
for i = n to 1
{
for j = 1 to i
print j
}
}

17. Continuous Number Pyramid


{
num = 1

for i = 1 to n
{
for j = 1 to i
{
print num
num++
}
}
}

18. Pascal’s Triangle


{
for i = 0 to n
{
value = 1

for j = 0 to i
{
print value
value = value * (i - j) / (j + 1)
}
}
}

19. X Pattern
{
for i = 1 to n
{
for j = 1 to n
{
if i==j or i+j==n+1
print "*"
else
print " "
}
}
}

20. Plus (+) Pattern


{
mid = n/2 + 1

for i = 1 to n
{
for j = 1 to n
{
if i==mid or j==mid
print "*"
else
print " "
}
}
}

21. Hollow Diamond


{
// use hollow pyramid logic
// combine upper and lower
}

22. Butterfly Pattern


{
// left stars
// middle spaces
// right stars
}

23. Sandglass Pattern


{
// inverted pyramid
// normal pyramid
}

24. Zig Zag Pattern


{
for i = 1 to 3
{
for j = 1 to n
{
if condition matches zigzag
print "*"
else
print " "
}
}
}
25. Hollow Right Triangle
{
for i = 1 to n
{
for j = 1 to i
{
if j==1 or j==i or i==n
print "*"
else
print " "
}
}
}

26. Numeric Pyramid


{
for i = 1 to n
{
for j = 1 to i
print i
}
}

27. Reverse Alphabet Triangle


{
for i = n to 1
{
ch = 'A'

for j = 1 to i
{
print ch
ch++
}
}
}

28. Mirror Right Triangle


{
for i = 1 to n
{
for s = 1 to i-1
print " "

for j = i to n
print "*"
}
}
29. Numeric Palindrome Pyramid
{
for i = 1 to n
{
for j = i to 1
print j

for j = 2 to i
print j
}
}

30. Alphabet Pyramid


{
for i = 1 to n
{
ch = 'A'

for j = 1 to i
{
print ch
ch++
}
}
}

31. Square Number Pattern


{
for i = 1 to n
{
for j = 1 to n
print i
}
}

32. Hollow Rectangle


{
for i = 1 to r
{
for j = 1 to c
{
if i==1 or i==r or j==1 or j==c
print "*"
else
print " "
}
}
}
33. Triangle of Zeros and Ones
{
for i = 1 to n
{
for j = 1 to i
print (j % 2)
}
}

34. Descending Number Pattern


{
for i = n to 1
{
for j = i to 1
print j
}
}

35. Continuous Alphabet Pattern


{
ch = 'A'

for i = 1 to n
{
for j = 1 to i
{
print ch
ch++
}
}
}

36. Hourglass Pattern


{
// inverted pyramid
// normal pyramid
}

37. Right Arrow Pattern


{
// upper triangle
// lower inverted triangle
}

38. Left Arrow Pattern


{
// mirror right arrow
}

39. Checkerboard Pattern


{
for i = 1 to n
{
for j = 1 to n
{
if (i+j) % 2 == 0
print "*"
else
print " "
}
}
}

40. Numeric Square


{
for i = 1 to n
{
for j = 1 to n
print j
}
}

41. Hollow Number Pyramid


{
for i = 1 to n
{
for j = 1 to i
{
if j==1 or j==i or i==n
print j
else
print " "
}
}
}

42. Diamond Number Pattern


{
// number pyramid
// inverted number pyramid
}
43. Alphabet Diamond
{
// alphabet pyramid
// inverted alphabet pyramid
}

44. Spiral Number Pattern


{
// use top, bottom, left, right
// fill matrix in spiral
}

45. Triangle of Squares


{
for i = 1 to n
{
for j = 1 to i
print j*j
}
}

46. Triangle of Cubes


{
for i = 1 to n
{
for j = 1 to i
print j*j*j
}
}

47. Number Cross Pattern


{
for i = 1 to n
{
for j = 1 to n
{
if i==j or i+j==n+1
print j
else
print " "
}
}
}
48. Hollow Plus Pattern
{
mid = n/2 + 1

for i = 1 to n
{
for j = 1 to n
{
if (i==mid or j==mid)
print "*"
else
print " "
}
}
}

49. Numeric Zigzag


{
// print numbers in zigzag rows
}

50. Custom Pattern


{
// analyze rows and columns
// apply conditions
}

Connect & Share:


Tag us on your success stories:

• Instagram: @code.abhii07
• YouTube: SYNTAX ERROR

You might also like