Google Interview experience
1 round over 3 weeks. No offer, good experience.
I was asked a leetcode array DSA question, and then we went over my resume and talked about my background. I thought it went okay but didn't move forward.
Question:
Given an array of intervals where each interval is represented as a pair of integers [start, end], merge all overlapping intervals and return an array of the non-overlapping intervals that cover all the intervals in the input.
Example Input:
[[1,3],[2,6],[8,10],[15,18]]Output:
[[1,6],[8,10],[15,18]]Intervals [1,3] and [2,6] overlap, so they are merged into [1,6].
The rest of the intervals do not overlap with any others.
def merge(intervals: List[List[int]]) -> List[List[int]]:
intervals.sort(key=lambda x: x[0])
merged_intervals = []
for interval in intervals:
# If merged_intervals is empty or current interval does not overlap with the last merged one
if not merged_intervals or merged_intervals[-1][1] < interval[0]:
merged_intervals.append(interval)
else:
# If there is an overlap, merge the current interval with the last one in merged_intervals
# by updating the end of the last interval to the maximum end value
merged_intervals[-1][1] = max(merged_intervals[-1][1], interval[1])
return merged_intervals
intervals = [[1, 3], [2, 6], [8, 10], [15, 18]]
result = merge(intervals)
print(result) # Output: [[1, 6], [8, 10], [15, 18]]Know someone interviewing at Google? Pass it on.
Same company, different candidates.
Share yours while it’s fresh. It takes five minutes, it’s anonymous, and it will help future candidates.