Coding Interviews
Coding Interviews
EP. 11
IN TEASHAYcoding
RV IENAYAK
N
W interview
ASHAY NAYAK
TOP T IO
UE S
Q
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
By Ashay Nayak Source: My Medium Article
ASHAY NAYAK
Hi Shreya! I am
Ashay. I am going
Hey Ashay! Thanks
for giving me this
ASHAY NAYAK
to take your oppportunity.
technical round.
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
By Ashay Nayak Source: My Medium Article
ASHAY NAYAK
I am going to ask
ASHAY NAYAK
few Coding
Questions. okay.
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
By Ashay Nayak Source: My Medium Article
ASHAY NAYAK
Given an m x n 2D binary
grid grid which
ASHAY NAYAK
represents a map of '1's
(land) and '0's (water),
ASHAY NAYAK
return the number of
hmm...
islands.
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
By Ashay Nayak
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
An island ('1') is surrounded by water ('0') and
is formed by connecting adjacent lands
ASHAY NAYAK
horizontally or vertically. You may assume all
four edges of the grid are all surrounded by
ASHAY NAYAK
water. See next page for examples
ASHAY NAYAK
ASHAY NAYAK
By Ashay Nayak Source: My Medium Article
ASHAY NAYAK
Examples
ASHAY NAYAK
ASHAY NAYAK
here, All 1's are connected either
horizontally or vertically. So,
ASHAY NAYAK
number of islands = 1
ASHAY NAYAK
ASHAY NAYAK
here, you will find 3 groups of 1's
which are separated by water ('0').
ASHAY NAYAK
So, number of islands = 3.
ASHAY NAYAK
ASHAY NAYAK
Union Find using rank and path
compression: Not recommended as it has
lengthy implementation. To learn union-find,
ASHAY NAYAK
search “union find hackerearth” on google and
it has provided a very good explanation. If you
ASHAY NAYAK
know this topic then check my article for
code. Link in comment. Let's move to next
ASHAY NAYAK
approach.
→ →
TC
ASHAY NAYAK
O(n*m) and SC O(n*m)
ASHAY NAYAK
ASHAY NAYAK
DFS (Depth First Search): Best Solution — it
ASHAY NAYAK
is standard DFS which we are applying for 2d
array. See next page for understanding it's
ASHAY NAYAK
implementation.
TC → ASHAY→NAYAK
O(n*m) and SC O(n*m)
ASHAY NAYAK
By Ashay Nayak Source: My Medium Article
COde
ASHAY NAYAK
BFS (Breadth First Search): Best Solution —
it is standard BFS which we are applying for 2d
array. ASHAY NAYAK
ASHAY NAYAK
If you are looking to understand this BFS
algorithm with code for interviews,
ASHAY NAYAK
then check out my article link given in the
ASHAY NAYAK
comment below.
→ →
TC
ASHAY NAYAK
O(n*m) and SC O(n*m)
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
ASHAY NAYAK
By Ashay Nayak Source: My Medium Article