0% found this document useful (0 votes)
214 views9 pages

Logic Build Pattern

The document outlines 15 LeetCode patterns with example questions and links, categorized into various algorithmic techniques such as Prefix Sum, Two Pointers, Sliding Window, and more. It also includes pseudocode for 15 different star and number patterns, providing a structured approach to solving common programming problems. Each section is designed to help learners understand and apply these patterns effectively.

Uploaded by

guruki054
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)
214 views9 pages

Logic Build Pattern

The document outlines 15 LeetCode patterns with example questions and links, categorized into various algorithmic techniques such as Prefix Sum, Two Pointers, Sliding Window, and more. It also includes pseudocode for 15 different star and number patterns, providing a structured approach to solving common programming problems. Each section is designed to help learners understand and apply these patterns effectively.

Uploaded by

guruki054
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
You are on page 1/ 9

15 LeetCode Patterns with Example Questions (with links)

Prefix Sum

303. Range Sum Query - Immutable

304. Range Sum Query 2D - Immutable

560. Subarray Sum Equals K

Two Pointers

88. Merge Sorted Array

15. 3Sum

27. Remove Element

Sliding Window

3. Longest Substring Without Repeating Characters

76. Minimum Window Substring

424. Longest Repeating Character Replacement

Fast & Slow Pointers

141. Linked List Cycle Click Here 👇


142. Linked List Cycle II THE BEARDED ENGINEER

287. Find the Duplicate Number

LinkedList In-place Reversal

206. Reverse Linked List

92. Reverse Linked List II

25. Reverse Nodes in k-Group

Monotonic Stack

84. Largest Rectangle in Histogram

739. Daily Temperatures

901. Online Stock Span


Binary Search

704. Binary Search

35. Search Insert Position

33. Search in Rotated Sorted Array

DFS

200. Number of Islands

102. Binary Tree Level Order Traversal

107. Binary Tree Level Order Traversal II

BFS

102. Binary Tree Level Order Traversal

127. Word Ladder

111. Minimum Depth of Binary Tree

Backtracking

46. Permutations

39. Combination Sum

78. Subsets
Click Here 👇
THE BEARDED ENGINEER
DP

70. Climbing Stairs

509. Fibonacci Number

198. House Robber

Topological Sort

207. Course Schedule

210. Course Schedule II

444. Sequence Reconstruction

Greedy Algorithms

455. Assign Cookies


45. Jump Game II

605. Can Place Flowers

Bit Manipulation

136. Single Number

191. Number of 1 Bits

260. Single Number III

Union Find

323. Number of Connected Components in an Undirected Graph

305. Number of Islands II

684. Redundant Connection

Click Here 👇
THE BEARDED ENGINEER 🌹
Top 15 Pattern Problems (With Pseudocode)

1. Right-Angled Triangle of Stars


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

Pseudocode:
for i in range(1, n+1):
print('* ' * i)

2. Inverted Triangle
* * * * *
* * * *
* * *
* *
*

Pseudocode:
for i in range(n, 0, -1):
print('* ' * i)

3. Square of Stars Click Here 👇


* * * * * * * * THE BEARDED ENGINEER 🌹
* * * * * * * *
* * * * * * * *
*

Pseudocode:
for i in range(n):
print('* ' * n)

4. Half Pyramid with Numbers


1
1 2
1 2 3
1 2 3 4
Pseudocode:
for i in range(1, n+1):
for j in range(1, i+1):
print(j, end=' ')
print()

5. Increasing Alphabets
A
A B
A B C
A B C D

Pseudocode:
for i in range(1, n+1):
for j in range(65, 65 + i):
print(chr(j), end=' ')
print()

6. Inverted Number Pyramid


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

Pseudocode: Click Here 👇


for i in range(n, 0, -1):
THE BEARDED ENGINEER 🌹
for j in range(1, i+1):
print(j, end=' ')
print()

7. Floyd's Triangle
1
2 3
4 5 6
7 8 9 10

Pseudocode:
num = 1
for i in range(1, n+1):
for j in range(1, i+1):
print(num, end=' ') num
+= 1
print()

8. 0-1 Triangle
1
0 1
1 0 1
0 1 0 1

Pseudocode:
for i in range(1, n+1):
for j in range(1, i+1):
print((i+j)%2, end=' ')
print()

9. Pascal's Triangle
1
1 1
1 2 1
1 3 3 1

Pseudocode:
def factorial(n):
return 1 if n == 0 else n * factorial(n-1)

for i in range(n):
for j in range(n - i - 1): Click Here 👇
print(' ', end=' ')
for j in range(i + 1):
THE BEARDED ENGINEER 🌹
print(factorial(i) // (factorial(j) * factorial(i - j)), end=' ')
print()

10. Number Pyramid


1 1 2
1 2 3 1
2 3 4

Pseudocode:
for i in range(1, n+1):
for j in range(n - i):
print(' ', end=' ')
for j in range(1, i+1):
print(j, end=' ')
print()

11. Diamond Pattern


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

Pseudocode:
# Upper half
for i in range(1, n+1):
print(' ' * (n - i) + '* ' * i)
# Lower half
for i in range(n-1, 0, -1):
print(' ' * (n - i) + '* ' * i)

12. Hollow Square


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

Click Here 👇
THE BEARDED ENGINEER 🌹

Pseudocode:
for i in range(n):
for j in range(n):
if i == 0 or i == n-1 or j == 0 or j == n-1:
print('*', end=' ')
else:
print(' ', end=' ')
print()

13. Butterfly Pattern


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

Pseudocode:
for i in range(1, n+1):
for j in range(1, i+1):
print('*', end=' ')
for j in range(2*(n - i)):
print(' ', end=' ')
for j in range(1, i+1):
print('*', end=' ')
print()

14. Palindromic Number Pattern


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

Pseudocode:
for i in range(1, n+1):
for j in range(i, 0, -1):
print(j, end=' ')
for j in range(2, i+1):
print(j, end=' ')
print()
Click Here 👇
15. Zig-Zag Pattern THE BEARDED ENGINEER 🌹
* *
* * * *
* * *

Pseudocode:
for i in range(1, 4):
for j in range(1, 10):
if (i + j) % 4 == 0 or (i == 2 and j % 4 == 0):
print('*', end=' ')
else:
print(' ', end=' ')
print()
THE BEARDED ENGINEER 🌹

You might also like