Coding Interview Questions
Coding Interview Questions
Copyright
by
Acknowledgements
I would like to express my gratitude to many people who saw me through this book, to all those who provided
support, talked things over, read, wrote, offered comments, allowed me to quote their remarks and assisted in
the editing, proofreading and design. In particular, I would like to thank the following individuals.
[
.
[
],
[
spending their valuable time in reviewing the book, suggestions and encouragement.
&
[Founders of
at their training centers.
] for
,
and
for your help and suggestions.
of
,
],
[
[
],
my family during our studies.
[
,
of
],
],
]&
M-Tech,
Founder of
Preface
Dear Reader,
Please Hold on! I know many people do not read preface. But I would like to strongly recommend reading
preface of this book at least. This preface has
from regular prefaces.
This book assumes you have some basic knowledge about computer science. Main objective of the book is not to
provide you all the interview questions. I have followed a pattern of improving the problem solutions with
different complexities (for each problem, you observe multiple solutions with different improved complexities
in data structure and algorithmic problems). Basically, it is an enumeration of possible solutions. With this
approach, even if we get a new question it gives us a way to think about all possible solutions. For all other
topics, it will act as refreshment. This book is very much useful for interview preparation, competitive exams
preparation and campus preparations.
As a
if you read complete book with good understanding, I am sure you will challenge the
interviewers and that is the objective of this book.
This book is very much useful for the
of
and
during their academic
preparations. All the chapters of this book contain theory and their related problems as many as possible. If you
read as a
preparing for competition exams for Computer Science/Information Technology], the content
of this book covers
the
topics in full details. While writing the book, an intense care has been
taken to help students who are preparing for these kinds of exams.
In most the chapters you will see more importance given to
and analyzing them instead of
concentrating more on theory. For each chapter, first you will see the basic required theory and then followed
by problems.
For many of the problems,
solutions are provided with different complexities. We start with
solution and slowly move towards the
possible for that problem. For each problem
we will try to understand how much time the algorithm is taking and how much memory the algorithm is
taking.
It is
that, at least one complete reading of this book is required to get full understanding of all
the topics. In the subsequent readings, you can directly go to any chapter and refer. Even though, enough
readings were given for correcting the errors, due to human tendency there could be some minor typos in the
book. If any such typos found, they will be updated at
. I request you to constantly
monitor this site for any corrections, new problems and solutions. Also, please provide your valuable
suggestions at:
.
Wish you all the best. Have a nice reading.
M-Tech,
Founder of
Table of Contents
Programming Basics ------------------------------------------------------------------------------9
Introduction ------------------------------------------------------------------------------------- 39
Recursion and Backtracking -------------------------------------------------------------------- 58
Linked Lists ------------------------------------------------------------------------------------- 63
Stacks -------------------------------------------------------------------------------------------- 99
Queues------------------------------------------------------------------------------------------ 122
Trees -------------------------------------------------------------------------------------------- 132
Priority Queue and Heaps --------------------------------------------------------------------- 202
Graph Algorithms ------------------------------------------------------------------------------ 218
Sorting ------------------------------------------------------------------------------------------ 246
Searching --------------------------------------------------------------------------------------- 266
Selection Algorithms [Medians] --------------------------------------------------------------- 291
Symbol Tables ---------------------------------------------------------------------------------- 300
Hashing ---------------------------------------------------------------------------------------- 302
String Algorithms ----------------------------------------------------------------------------- 316
Algorithms Design Techniques ---------------------------------------------------------------- 337
Greedy Algorithms----------------------------------------------------------------------------- 340
Divide and Conquer Algorithms -------------------------------------------------------------- 349
Dynamic Programming ----------------------------------------------------------------------- 355
Complexity Classes----------------------------------------------------------------------------- 392
Design Interview Questions ------------------------------------------------------------------- 398
Operating System Concepts ------------------------------------------------------------------- 454
Computer Networking Basics------------------------------------------------------------------ 461
Database Concepts ----------------------------------------------------------------------------- 474
Brain Teasers ----------------------------------------------------------------------------------- 480
Non-Technical Help --------------------------------------------------------------------------- 483
Miscellaneous Concepts ----------------------------------------------------------------------- 488