0% found this document useful (0 votes)
3 views23 pages

Coding Patterns

The document outlines 20 coding patterns essential for data structures and algorithms (DSA), providing usage, data structures involved, and sample problems for each pattern. It emphasizes the importance of understanding these concepts at one's own pace rather than rushing through them. Additionally, it highlights the benefits of learning from Bosscoder, including alumni success and average salary packages.

Uploaded by

zhbalam05
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)
3 views23 pages

Coding Patterns

The document outlines 20 coding patterns essential for data structures and algorithms (DSA), providing usage, data structures involved, and sample problems for each pattern. It emphasizes the importance of understanding these concepts at one's own pace rather than rushing through them. Additionally, it highlights the benefits of learning from Bosscoder, including alumni success and average salary packages.

Uploaded by

zhbalam05
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/ 23

20

Coding
Patterns
22 44 00 66 11 4400

0 0 1 2
001 24464 4 6
crack any coding interview
*Disclaimer*

Learning all 20 Coding Patterns in DSA can be a

challenging journey.

Go at your own pace, take breaks when needed,

and remember, it’s not about how fast you finish,

but how well you understand. Use this doc as

your guide, and build a solid foundation in DSA.


Sliding Window
Usage : This algorithmic technique is used when
we need to handle the input data in a specific
window size.

DS Involved : Array, String, HashTable

Sample Problems :
Longest Substring with 'K' Distinct Characters
Fruits into Baskets
2. Islands

(Matrix Traversal)
Usage : This pattern describes all the efficient

ways of traversing a matrix (or 2D array).

DS Involved : Matrix, Queue

Sample Problems :
Number of Islands
Flood Fill
Cycle in a Matrix
3. Two Pointers

Usage : This technique uses two pointers to


iterate input data. Generally, both pointers move in
the opposite direction at a constant interval.

DS Involved : Array, String, LinkedList

Sample Problems :
Squaring a Sorted Array
Dutch National Flag Problem
Minimum Window Sort
4. Fast & Slow Pointers

Usage : Also known as Hare & Tortoise algorithm.


This technique uses two pointers that traverse the
input data at different speeds.

DS Involved : Array, String, LinkedList

Sample Problems :
Middle of the LinkedList
Happy Number
Cycle in a Circular Array

Head Cycle Start


5. Merge Intervals

Usage : This technique is used to deal with

overlapping intervals.

DS Involved : Array, Heap

Sample Problems :
Conflicting Appointments
Minimum Meeting Rooms

er “a”

er “b”

a
6. Cyclic Sort

Usage : Use this technique to solve array

problems where the input data lies within a

fixed range.

DS Involved : Array

Sample Problems :
Find all Missing Numbers
Find all Duplicate Numbers
Find the First K Missing Positive Numbers

0
In-place Reversal of a
LinkedList
Usage : This technique describes an efficient

way to reverse the links between a set of nodes

of a LinkedList. Often, the constraint is that we

need to do this in-place, i.e., using the existing

node objects and without using extra memory.

DS Involved : LinkedList

Sample Problems :
Reverse every K-element Sub-list
Rotate a LinkedList
8. Breadth-First Search

Usage : This technique is used to solve problems


involving traversing trees or graphs in a breadth-
first search manner.

DS Involved : Tree, Graph, Matrix, Queue

Sample Problems :
Binary Tree Level Order Traversal
Minimum Depth of a Binary Tree
Connect Level Order Siblings
Depth First Search

Usage : This technique is used to solve

problems involving traversing trees or graphs in

a depth-first search manner.

DS Involved : Tree, Graph, Matrix

Sample Problems :
Path With Given Sequence
Count Paths for a Sum
10. Two Heaps

Usage : In many problems, we are given a set of elements


that can be divided into two parts. We are interested in
knowing the smallest element in one part and the biggest
element in the other part. As the name suggests, this
technique uses a Min-Heap to find the smallest element and
a Max-Heap to find the biggest element.

DS Involved : Heap, Array


Sample Problems :
Find the Median of a Number Stream
Next Interval

Max Heap Min Heap

1 6

Median = (Top of Max Heap (3) + (4) Top of Min Heap)/ 2

= (3 + 4)/ 2

= 3.5
11. Subsets

Usage : Use this technique when the problem

asks to deal with permutations or combinations

of a set of elements.

DS Involved : Queue, Array, String

Sample Problems :
String Permutations by changing case
Unique Generalized Abbreviations
12. Modified Binary Search

Usage : Use this technique to search a sorted

set of elements efficiently.

DS Involved : Array

Sample Problems :
Ceiling of a Number
Bitonic Array Maximum
Bitwise XOR

Usage : This technique uses the XOR operator

to manipulate bits to solve problems.

DS Involved : Array, Bits

Sample Problems :
Two Single Numbers
Flip and Invert an Image
14. Top ‘K’ Elements

Usage : This technique is used to find top/


smallest/frequently occurring ‘K’ elements in

a set.

DS Involved : Array, Heap, Queue

Sample Problems :
‘K’ Closest Points to the Origin
Maximum Distinct Elements

K=3
K-way Merge

Usage : This technique helps us solve problems

that involve a list of sorted arrays.

DS Involved : Array, Queue, Heap

Sample Problems :
Kth Smallest Number in M Sorted Lists
Kth Smallest Number in a Sorted Matrix

Sorted :
Topological Sort

Usage : Use this technique to find a linear

ordering of elements that have dependencies

on each other.

DS Involved : Array, HashTable, Queue, Graph

Sample Problems :
Tasks Scheduling
Alien Dictionary
17. 0/1 Knapsack

Usage : This technique is used to solve

optimization problems. Use this technique to

select elements that give maximum profit from

a given set with a limitation on capacity and that

each element can only be picked once.

DS Involved : Array, HashTable

Sample Problems :
Equal Subset Sum Partition
Minimum Subset Sum Difference
18. Fibonacci Numbers

Usage : Use this technique to solve problems that


follow the Fibonacci numbers sequence, i.e., every
subsequent number is calculated from the last few
numbers.

DS Involved : Array, Hash Table

Sample Problems :
Staircase
House Thief

12,7
19. Palindromic
Subsequence
Usage : This technique is used to solve

optimization problems related to palindromic

sequences or strings.

DS Involved : Array, HashTable

Sample Problems :
Longest Palindromic Subsequence
Minimum Deletions in a String to make it a

Palindrome
20. Longest Common
Substring
Usage : Use this technique to find the optimal part
of a string/sequence or set of strings/sequences.

DS Involved : Array, HashTable

Sample Problems :
Maximum Sum Increasing Subsequence
Edit Distance
Why Bosscoder?
2200+ Alumni placed at Top Product-
based companies.

More than 120% hike for every 



2 out of 3 Working Professional.

Average Package of 24LPA.

Explore More

You might also like