Code Challenge
How to Solve It
- First, you have to understand the problem.
- After understanding, make a plan.
- Carry out the plan.
- Look back on your work. How could it be better?
If this technique fails, Pólya advises: "If you can't solve a problem, then there is an easier problem you can solve: find it." Or: "If you cannot solve the proposed problem, try to solve first some related problem. Could you imagine a more accessible related problem?"
Patterns
Sliding Window
Usage: This algorithmic technique is used when we need to handle
the input data in specific window size.
Two Pointers
Usage: In this technique, we use two pointers to iterate the input
data. Generally, both pointers move in the opposite direction at a
constant interval.
Fast & Slow Pointers
Usage: Also known as Hare & Tortoise algorithm. In this technique,
we use two pointers that traverse the input data at a different speed.
Merge Intervals
Usage: This technique is used to deal with overlapping intervals.
Given two intervals (‘a’ and ‘b’), there will be six different ways
the two intervals can relate to each other:
Cyclic Sort
Usage: Use this technique to solve array problems where the input data
lies within a fixed range.
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.
Tree Breadth-First Search
Usage: As the name suggests, this technique is used to solve problems
involving traversing trees in a breadth-first search manner.
Tree Depth First Search
Usage: As the name suggests, this technique is used to solve problems
involving traversing trees in depth-first search manner.
Two Heaps
Usage: In many problems, where we are given a set of elements such that
we can divide them 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.
Subsets
Usage: Use this technique when the problem asks to deal with permutations
or combinations of a set of elements.
Modified Binary Search
Usage: Use this technique to search a sorted set of elements efficiently.
Bitwise XOR
Usage: This technique uses the XOR operator to manipulate bits to
solve problems.
Top ‘K’ Elements
Usage: This technique is used to find top/smallest/frequently occurring
‘K’ elements in a set.
K-way Merge
Usage: This technique helps us solve problems that involve a list of
sorted arrays.
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.
Unbounded Knapsack
Usage: Use this technique to select elements that give maximum profit
from a given set with a limitation on capacity and that each element
can be picked multiple times.
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.
Palindromic Subsequence
Usage: This technique is used to solve optimization problems related
to palindromic sequences or strings.
Longest Common Substring
Usage: Use this technique to find the optimal part of a string/sequence
or set of strings/sequences.
Topological Sort
Usage: Use this technique to find a linear ordering of elements that
have dependencies on each other.
Trie Traversal
Usage: Use this technique that involves creating or traversing of
Trie data structure.
Number of Island
Usage: Use this technique to traverse a two-dimensional array and
find a set of connected elements.
Trial & Error
Usage: Use this technique to traverse an array to find a required
optimal element. The traversal process runs in a trial & error manner.
Union Find
Usage: Use this technique to solve problems that require maintaining
a given set of elements partitioned into multiple non-overlappin
g subsets.
Unique Paths
Usage: Use this technique to find different/optimal ways to traverse
a multi-dimensional array.