Software Prep Guide
Software Prep Guide
Software Prep Guide
Software companies
1) C++ STL
SUM on lower_bound:
https://www.hackerrank.com/challenges/cpp-lower-
bound
Refer the below link for the algorithms library.
https://www.geeksforgeeks.org/c-magicians-stl-
algorithms/
Vector:
Vector is basically an array which can do a lot more
than a normal array! (Assume it like an array)
one way to define a vector in c++ is vector<int> v ;
v is the name of the vector.
SUM: https://www.hackerrank.com/challenges/cpp-
sets
Priority queue(heap) , stack , queue:
https://www.geeksforgeeks.org/priority-queue-in-cpp-
stl/
https://www.geeksforgeeks.org/stack-in-cpp-stl/
https://www.geeksforgeeks.org/queue-cpp-stl/
these are fairly simple to catch up with, so have a look.
Pair:
Pair ds is also pretty important, we personally had to
use pair< > to solve a lot of questions.
Again, there are various ways to use it like pair<int,int>
p;
pair<string,int>p;
pair<char,int>p;
etc depending on your need.
Depending on the question if you think in your data
structure you need some more data you could always
use pair as well.
Let’s say you are trying to solve something and for that
you need to take account for the element and the
index.
So here we can use pair.
vector<pair<int,int>>v;
Let’s say arr is the name of the vector.
for(int i=0;i<arr.size();i++)
{
V.push_back( {arr[i],i} );
}
This is the syntax we use while inserting and if we want
to access, we access using .first and .second
Like v[i].first; v[i].second;
https://www.geeksforgeeks.org/pair-in-cpp-stl/
2) Binary search
Binary Search is quite an underrated concept but it is
actually a very good concept to learn and start coding
with.
Keeping it short, this is the playlist to watch:
https://www.youtube.com/watch?v=j7NodO9HIbk&list
=PL_z_8CaSLPWeYfhtuKHj-9MpYb6XQJ_f2
This playlist is very important, please watch all the
videos, and the last video is THE MOST IMPORTANT
video in binary search. Till now for final year
placements 5 top tech companies have asked based on
the concept of the last video in the playlist
Sums to Practice:
Short note before you start, no matter if you get 100%
to your solution or you fail to solve it.
DO GO THE DISCUSSIONS SECTION and have a look at
other solutions posted, this is where the most of the
learning takes place.
1) https://leetcode.com/problems/count-negative-
numbers-in-a-sorted-matrix
2) https://leetcode.com/problems/find-smallest-letter-
greater-than-target
3) https://leetcode.com/problems/search-insert-
position
4) https://leetcode.com/problems/valid-perfect-square
5) https://leetcode.com/problems/first-bad-version
6) https://leetcode.com/problems/sqrtx
3) Stack:
Stack is a very versatile data structure which can be
used in substantially different situations:
This is the playlist:
https://www.youtube.com/watch?v=P1bAPZg5uaE&lis
t=PL_z_8CaSLPWdeOezg68SKkeLN4-T_jNHd
SUMS:
1) https://leetcode.com/problems/remove-all-
adjacent-duplicates-in-string
2) https://leetcode.com/problems/next-greater-
element-i
3) https://leetcode.com/problems/min-stack
4) https://leetcode.com/problems/valid-parentheses
5) https://leetcode.com/problems/minimum-add-to-
make-parentheses-valid
6) https://leetcode.com/problems/daily-
temperatures
7) https://leetcode.com/problems/next-greater-
node-in-linked-list
8) https://leetcode.com/problems/remove-all-
adjacent-duplicates-in-string-ii
9) https://leetcode.com/problems/asteroid-collision
10) https://leetcode.com/problems/longest-well-
performing-interval
11) https://leetcode.com/problems/trapping-rain-
water
12) https://leetcode.com/problems/largest-
rectangle-in-histogram
2) string.substr(index,length):
Similar to erase function right! In terms of
arguments of course. This is used to get a Sub-
string from a string. Let me directly jump into the
example.
Example: let string str = “HakunaMatata”;
str.substr(6,6) return a string as “Matata”
3) to_string(any_type_num): This converts
any type of number be it integer type, float type,
long, double etc. into a string.
For ex: if double x=12.06;
to_string(x) returns a string “12.06”;
4) stoi(string):
This converts a string into integer (digits in string).
PS: It should be a valid case.
This can come in very handy when we are dealing
with big numbers > INT_MAX or when we want to
play around with digits. You can easily count
number of digits without much code.
sorted-array-ii/
51) https://leetcode.com/problems/grumpy-
bookstore-owner/
52) https://leetcode.com/problems/divide-array-in-
sets-of-k-consecutive-numbers/
53) https://leetcode.com/problems/rank-teams-by-
votes/
54) https://leetcode.com/problems/container-with-
most-water/
55) https://leetcode.com/problems/task-scheduler/
56) https://leetcode.com/problems/reorganize-string/
57) https://leetcode.com/problems/word-subsets/
58) https://leetcode.com/problems/minimum-number-
of-frogs-croaking/
59) https://leetcode.com/problems/basic-calculator-ii/
60) https://leetcode.com/problems/replace-the-
substring-for-balanced-string/
61) https://leetcode.com/problems/valid-parenthesis-
string/
62) https://leetcode.com/problems/longest-substring-
without-repeating-characters/
63) https://leetcode.com/problems/can-convert-string-
in-k-moves/
64) https://leetcode.com/problems/shortest-unsorted-
continuous-subarray/
65) https://leetcode.com/problems/lucky-numbers-in-
a-matrix/
66) https://leetcode.com/problems/sort-array-by-
parity-ii/
67) https://leetcode.com/problems/find-common-
characters/
68) https://leetcode.com/problems/top-k-frequent-
elements/
69) https://leetcode.com/problems/relative-sort-
array/
70) https://leetcode.com/problems/find-words-that-
can-be-formed-by-characters/
71) https://leetcode.com/problems/maximum-score-
after-splitting-a-string/
72) https://leetcode.com/problems/first-unique-
character-in-a-string/
73) https://leetcode.com/problems/repeated-
substring-pattern/
74) https://leetcode.com/problems/valid-palindrome-
ii/
75) https://leetcode.com/problems/minimum-
absolute-difference/
76) https://leetcode.com/problems/toeplitz-matrix/
77) https://leetcode.com/problems/fair-candy-swap/
78) https://leetcode.com/problems/monotonic-array/
79) https://leetcode.com/problems/find-the-minimum-
number-of-fibonacci-numbers-whose-sum-is-k/
80) https://leetcode.com/problems/product-of-array-
except-self/
81) https://leetcode.com/problems/longest-subarray-
of-1s-after-deleting-one-element/
82) https://leetcode.com/problems/rotate-image/
83) https://leetcode.com/problems/number-of-
substrings-containing-all-three-characters/
84) https://leetcode.com/problems/group-anagrams/
85) https://leetcode.com/problems/maximum-
number-of-vowels-in-a-substring-of-given-length/
86) https://leetcode.com/problems/smallest-
subsequence-of-distinct-characters/
Recursion:
Quick Note: As you have come this far, it would be a
good time to start preparing OOP and DBMS. Start with
OOPS, study it parallelly while practicing coding.
https://www.youtube.com/watch?v=kHi1DUhp9kM&li
st=PL_z_8CaSLPWeT1ffjiImo0sYTcnLzo-wY
watch this playlist to get a good understanding, if you
still aren’t able to understand, please refer other
videos as well on YouTube!
please see the discussions page on leetcode for every
recursive problem we do from now on. It might be
annoying we are repeating it so many times, but trust
me your learning will be exponential if you refer the
discussions page
Backtracking:
Backtracking is the best way to get a hang of recursion,
it is a very good way to start off.
Always remember backtracking is very costly so only if
the input is small, then we apply backtracking or else
we try to approach using different concept.
Watch the below video to get the best understanding
of backtracking.
https://www.youtube.com/watch?v=jFwREev_yvU&t=
1075s
Trees:
A lot of people are very afraid of trees, but trees are
very easy, the point being all tree questions are
somewhat similar except a few changes here and
there. The first and the most important thing is to
understand tree traversals (preorder , inorder ,
postorder).The most important types of trees here are
the binary and the binary search tree.
You will easily understand trees if you are good at
recursion.
Trees we either do DFS (recursion manner) or a BFS
(iterative using a queue) depending on the question.
Example a level order traversal would be easy if we use
queue and BFS, although we can do it using DFS using
recursion as well.
some problems to do
1) https://leetcode.com/problems/merge-two-
binary-trees
2) https://leetcode.com/problems/sum-of-root-to-
leaf-binary-numbers
3) https://leetcode.com/problems/maximum-depth-
of-binary-tree
4) https://leetcode.com/problems/invert-binary-tree
5) https://leetcode.com/problems/average-of-levels-
in-binary-tree
6) https://leetcode.com/problems/binary-tree-level-
order-traversal-ii
7) https://leetcode.com/problems/same-tree
8) https://leetcode.com/problems/deepest-leaves-
sum/
9) https://leetcode.com/problems/sum-of-nodes-
with-even-valued-grandparent/
10) https://leetcode.com/problems/insert-into-a-
binary-search-tree/
11) https://leetcode.com/problems/lowest-
common-ancestor-of-deepest-leaves/
12) https://leetcode.com/problems/maximum-
difference-between-node-and-ancestor/
13) https://leetcode.com/problems/find-bottom-
left-tree-value/
14) https://leetcode.com/problems/find-largest-
value-in-each-tree-row/
15) https://leetcode.com/problems/smallest-
subtree-with-all-the-deepest-nodes/
16) https://leetcode.com/problems/kth-smallest-
element-in-a-bst/
17) https://leetcode.com/problems/most-
frequent-subtree-sum/
18) https://leetcode.com/problems/construct-
binary-tree-from-preorder-and-inorder-traversal
trees might not be asked in an OT usually, but there is
a high probability trees might be asked in an interview.
Please refer the discussions page for each tree
problem.
There are many more problems on trees, we are only
giving some of the good conceptual questions on trees,
you can do other problems on leetcode if you wish.
Linked Lists:
Watch this video to get an idea about linked lists.
https://www.youtube.com/watch?v=dmb1i4oN5oE
Dynamic programming:
Yes, we are finally here. One of the most important
topics and companies just LOVE to ask questions based
on Dynamic programming. All companies with a high
CTC always try to ask based on dynamic programming
The following playlist of Aditya verma is all about DP, a
lot of good questions he picked up. Believe me, no one
can explain better than him.
If you want to get GOOD at DP, watch all his videos in
the playlist and try to code it one by one. It will give
you a very good head start.
The following videos are very important.
https://www.youtube.com/watch?v=nqowUJzG-
iM&list=PL_z_8CaSLPWekqhdCPmFohncHwz8TY2Go
1) https://leetcode.com/problems/min-cost-
climbing-stairs
2) https://leetcode.com/problems/climbing-stairs
3) https://leetcode.com/problems/maximum-
subarray
4) https://leetcode.com/problems/house-robber
5) https://leetcode.com/problems/count-square-
submatrices-with-all-ones
6) https://leetcode.com/problems/partition-array-
for-maximum-sum
7) https://leetcode.com/problems/minimum-falling-
path-sum
8) https://leetcode.com/problems/palindromic-
substrings
9) https://leetcode.com/problems/longest-common-
subsequence
10) https://leetcode.com/problems/arithmetic-
slices
11) https://leetcode.com/problems/minimum-
path-sum
12) https://leetcode.com/problems/unique-paths
13) https://leetcode.com/problems/longest-
arithmetic-subsequence
14) https://leetcode.com/problems/integer-break
15) https://leetcode.com/problems/largest-sum-
of-averages
16) https://leetcode.com/problems/maximum-
length-of-repeated-subarray
17) https://leetcode.com/problems/delete-and-
earn
18) https://leetcode.com/problems/number-of-
dice-rolls-with-target-sum
19) https://leetcode.com/problems/perfect-
squares
20) https://leetcode.com/problems/best-time-to-
buy-and-sell-stock-with-cooldown
21) https://leetcode.com/problems/greatest-
sum-divisible-by-three
22) https://leetcode.com/problems/target-sum
23) https://leetcode.com/problems/partition-to-
k-equal-sum-subsets
24) https://leetcode.com/problems/triangle
25) https://leetcode.com/problems/partition-
equal-subset-sum
26) https://leetcode.com/problems/ones-and-
zeroes
27) https://leetcode.com/problems/longest-
increasing-subsequence
28) https://leetcode.com/problems/word-break
29) https://leetcode.com/problems/largest-
divisible-subset
30) https://leetcode.com/problems/maximal-
square
31) https://leetcode.com/problems/coin-change
32) https://leetcode.com/problems/longest-
palindromic-substring
33) https://leetcode.com/problems/decode-ways
34) https://leetcode.com/problems/palindrome-
partitioning-iii
35) https://leetcode.com/problems/burst-
balloons
36) https://leetcode.com/problems/shortest-
common-supersequence
37) https://leetcode.com/problems/minimum-
cost-to-cut-a-stick
38) https://leetcode.com/problems/edit-distance
39) https://leetcode.com/problems/remove-
boxes
40) https://leetcode.com/problems/maximum-
sum-bst-in-binary-tree
41) https://leetcode.com/problems/interleaving-
string
42) https://leetcode.com/problems/minimum-
number-of-refueling-stops
43) https://leetcode.com/problems/longest-valid-
parentheses
44) https://leetcode.com/problems/best-time-to-
buy-and-sell-stock-iv
45) https://leetcode.com/problems/regular-
expression-matching
Graphs:
Graphs is a complex data structure, it has been asked
recently In a good number of companies. it is good to
know the basics of graphs and solve a few questions to
be prepared to tackle graph problems.
Here are the few topics we will cover in graphs
1) Building a graph
2) DFS
3) BFS
4) Cycle in graph
5) Toplogical sort
6) Union find
7) Connected components
8) Graph colouring
9) Graph algorithms like prim, dijkshta (idk the
spelling) and so on!
Building a graph
There are various methods to build a graph, usually
your input is a vector<vector<int,int>>v , which is a nx2
matrix representing the edges that are connecting 2
nodes.
DFS and BFS
This is the basic types of problems that we might
expect from a graph type question.
To be able to do any DFS or BFS problem, you will need
to understand the concept of visited array.
Meaning in a normal DFS or a BFS we do not want to
visit the same node again, so we usually keep a visited
array and mark the node as visited as soon as we reach
it and then we call another dfs to a node provided it is
not visited already.
https://www.youtube.com/watch?v=pcKY4hjDrxk&t=4
s
watch the above video to cover the DFS and BFS
concepts.
This is my syntax, how I usually do a DFS or a BFS, feel
free to check out other methods if you aren’t able to
follow mine!
Cycle in a graph
This is an important concept, there can be a lot of
questions which are coming under this topic. there is a
cycle for directed graph and for undirected graph.
Follow the videos to understand better
https://www.youtube.com/watch?v=0dJmTuMrUZM
https://www.youtube.com/watch?v=6ZRhq2oFCuo
Topological sort
This is important when the order of something
matters, meaning if there is an edge from u->v
topological sort always tells that u must be visited
before v. it will be easier if you watch a video than me
explaining loool.
https://www.youtube.com/watch?v=qe_pQCh09yU&t
=674s
union find
union find problems are a bit hard to figure out that we
have to actually use union find here, but once we know
they are pretty easy to solve.
https://www.youtube.com/watch?v=eTaWFhPXPz4
union find further helps in finding the number of
connected components in an undirected graph and
also cycle detection in an undirected graph.
Connected components
Given an undirected graph, if you understood the
concept of union find, then after we perform union
find. we can run a for loop to check if par[i]== i, and we
do a count++, and we can get the number of connected
components
https://www.youtube.com/watch?v=ymxPZk7TesQ
this is another simple way to find the connected
components in an undirected graph, which is to count
the number of DFS calls made, this is simpler compared
to the above method.
https://www.youtube.com/watch?v=9esCn0awd5k&t=
366s
graph colouring
graph colouring is used in various ways, to detect
cycles or to separate nodes from each other or
something.
https://www.youtube.com/watch?v=_sdVx_dWnlk
https://www.youtube.com/watch?v=0ACfAqs8mm0&t
=1168s
https://www.youtube.com/watch?v=L0DcePeWHnM&
t=92s
graph algorithms
there are N number of sources available for this,
usually when we say graphs everyone suggests to learn
these like prims, kruskals, Dijkstra, Floyd and so on... so
have a look on YouTube and geeksforgeeks.
Dijkstra is the MOST important out of all of these.
https://www.youtube.com/watch?v=XB4MIexjvY0&t=5
72s
https://www.youtube.com/watch?v=4ZlRH0eK-
qQ&t=507s
https://www.youtube.com/watch?v=FtN3BYH2Zes&t=
402s
Grid problems:
Here you have to apply a DFS or a BFS , you will be
given the directions you are allowed to travel and
based on that you will have to make recursive calls , do
check for boundary conditions in DFS meaning , you
should always stay in the grid , while doing recursion
take care of that , meaning if you are in the 0 th row
during some recursive call you cannot do a dfs(i-
1,j,grid) which will make you go out of bounds.
https://www.youtube.com/watch?v=__98uL6wst8
watch the above video to get an idea.
Access specifiers
there are 3 access specifiers in C++, public, private and
protected.
The public members can be used inside and outside
the class, the private members can be used only inside
the class and cannot be used outside the class.
Protected members can be used inside the class and
inherited classes and cannot be used outside classes.
Hope you have understood the error.
Access specifiers are important as they are used to
implement abstraction and data hiding and types of
inheritance and etc.
Data hiding
In our Kart of Team Tejas(❤❤), we have certain
critical wire connections going to the motor which can
be altered to change the working of the motor,
basically any changes in wire might affect its operation,
so what we did was we completely enclosed the motor
such that the wires are completely hidden and no
accidental changes can be made which might affect its
operation.
Basically, as a manufacturer it is your responsibility to
keep the critical data safe for proper functioning.
Let’s take another software example now, let’s say we
have a class student and we have int age; defined as
public, so it can be used outside the class. Now let’s say
a person comes and makes the age of some student
while creating the object as negative, as we know the
age cannot be negative. But since we have made it
public, it is accessible and it is prone to unwanted or
bad changes which might affect the operations. So
what is the solution is, we make age as private instead,
and create a public function, the public function inside
the class can access the private data and update the
value, before updating we can check if the age Is
negative and if negative we can return a prompt saying
it is invalid or something. So hopefully you understood
what exactly data hiding is and why we need it.
In a way if we look at it, data hiding allows us to have
better control over our software, if it were public we
would have no control and the user could do anything,
but using the access specifiers and then making age
private and then doing some checking, we are having
better control over our software.
Encapsulation
Encapsulation essentially wraps up or combines the
data members and member functions into a single
unit. Usually the data is kept private and the functions
which are used to manipulate the data are kept as
public members. In a way we can say that
encapsulation helps in achieving the data hiding
concept.
So, you can also explain the data hiding examples
saying they can be achieved using the encapsulation.
So, encapsulation is basically some data hiding and
abstraction.
Classic example is a medicine or a capsule, the
medicine has a lot of combinations and all, and it is all
into a single unit. Like those 2 coloured medicine, one
colour we can say they are data members and the
other half colour is the member functions but in a
whole, both form as one single unit.
Constructors
Constructor simply initialises an object. Basically, the
object gets all the resources allocated.
So, when exactly is a constructor called, essentially we
can manually create a constructor, or if not a
constructor is automatically called by the compiler
when we create an object.
Student s ;
This statement automatically calls a constructor, the
compiler takes care of it and calls the constructor. It
allocates all the memory needed for the object, for
example when we create object s of student type, all
the members of student class like roll.no, name, age
etc will be automatically created.
We can also define our own constructor, there are 3
ways to do it
1) Default constructor
2) Parameterised constructor
3) Copy constructor.
To understand this concept, let us take an example and
learn, Let’s say you go to a shop to buy a pen, if you
just ask for a pen without mentioning any
specifications, he might give you a normal pen of say
blue colour. This is an example of default constructor,
you don’t specify anything particularly and complier
gives an object with random garbage values in data
members.
Next, Parameterised constructor, now let’s say you go
to the pen shop again but this time you specify the
colour of the pen, brand of the pen etc. this time he
gives you that particular pen. So parameterised
constructor takes all the parameters, creates an object
with those parameters.
Finally, Copy constructor, now you go to the pen shop
again and this time you take a old pen, show it to the
shopkeeper and ask him to give a similar pen. Then he
gives you that particular type of pen. So, a copy
constructor takes an object as an example and creates
an object with same parameters as the example and
gives you the new object.
Destructors
They delete an object when the object goes out of
scope.
https://www.geeksforgeeks.org/destructors-c/
Polymorphism
Polymorphism means many forms. The classic
examples are humans! We show different forms
according to the situation and the people we are
around!
we are the same person, but we tend to show a
different form at different times.
Under polymorphism there are 3 things to pay
attention to
1)function overloading (compile time)
2) function overriding (run time)
3) operator overloading
Function overloading, essentially the functions have
the same name but have different parameters.