Facebook | Phone Screen | USA | SDE

1015
Dec 01, 2021
Dec 02, 2021

Q1
Given a string, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string only consists of lowercase English letters.

Input: "aba"
Output: False

Input: "abab"
Output: True

Explanation: It's the substring "ab" twice.

Input: "abcabcabcabc"
Output: True

Explanation: It's the substring "abc" four times. (And the substring "abcabc" twice.)

Q2
Given a binary array, find the maximum length of a contiguous subarray with equal numbers of 0 and 1.

Input: [0,1]
Output: 2
Explanation: [0, 1] is the longest contiguous subarray with equal numbers of 0 and 1.

Input: [0,1,0]
Output: 2
Explanation: [0, 1] (or [1, 0]) is a longest contiguous subarray with equal numbers of 0 and 1.

Input: [0,1,0,0,1]
Output: 4
Explanation: [1, 0, 0, 1] is a longest contiguous subarray with equal numbers of 0 and 1.

Input: [1,0,0,0,1]
Output: 2
Explanation: [1, 0](or [0, 1]) is a longest contiguous subarray with equal numbers of 0 and 1.

Was given 40 mins aprox 20 mins for each question. Wasnt able to get optimal solution for Q2 used brute force and got a n^2 solution.

Comments (9)