Facebook | Phone | Number of Islands & Maximum vacation length
Location: HQ, Menlo Park.
I was asked to solve 2 questions.
1. Number of islands (variation)
Given M x N ocean (matrix), returnan array of areas of islands surrounded by water.
Variation: An island is considered to be connected in all 8 directions (top, bottom, left, right, top-left, top-right, bottom-left, bottom-right)
1 1 0 0 1
0 1 0 1 1
1 0 0 1 1
1 0 0 0 0 int[] findAreaOfIslands(int[][] ocean) should return int array [5, 5]
I was able to solve this fairly quickly (~ 20 mins), discussed about time and space complexities. Then the interviewer presented with following sliding window problem.
2. Maximum vacation length
Variation of https://leetcode.com/problems/max-consecutive-ones-iii/
Given boolean array of days at work, [T, F, T, T, F, F, F, T] and pto (number of PTOs one can take) - where boolean T means paid holiday and F means you can take a PTO. Find the maximum length of vacation an employee can take.
int findMaxVacationLength(year = [F, T, F, T, F, T, F, ], pto = 2) should return 5 because if we take PTO on indices year[2] and year[4], then we can get the maximum length vacation (consecutive T's).
I couldn't complete the code implenmentation for this, neither could I come up with sliding window solution. I discussed brute force approach and time and space complexities.
Update: Got a call from recruiter and invited me for the onsite-interviews.


