Zeta TECH | Round 1 | DSA | Selected
Anonymous User
732
  1. Q1. Given an row of seats containing 0's and 1's, where 0 means empty and 1 means not empty, and an integer n, return if n new persons can be seated in the row without violating the no-adjacent-persons rule.
Example 1:

Input: row = [1,0,0,0,1], n = 1
Output: true

Example 2:
Input: row = [1,0,1,0,1], n = 2
Output: false

[1,0,1,0,1,0,1,0,1] n = 0

Ex 4:[1,0,1,0,1], person = -1

Level : Easy- Medium

Q2.
You are given an n x n binary matrix grid where 1 represents land and 0 represents water.

An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid.

You may change 0's to 1's to connect the two islands to form one island.

Return the smallest number of 0's you must flip to connect the two islands.

Example 1:

Input: grid = [
        [0,1],
        [1,0]]
Output: 1





Example 2:

Input: grid = [[0,1,0],
             [0,0,0],
             [0,0,1]]
Output: 2

Level : Medium

Comments (4)