Google SWE2 | Phone Screen | Rejected
Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2025-04-25Added By Anonymous
Source:ย Link
๐งญ Experience: 2 YOE
โ Outcome: Rejected after phone screen
๐ฐ Compensation: unknown
๐ Location: unknown
๐ข Company: Google
๐ Education: unknown
๐ Benefits: unknown
๐ Offer Date: unknown
๐ Company: Google
๐ Round: Phone Screen
๐ง Role: SDE-2
๐๏ธ Experience: 2 YOE
โ Status: Rejected after phone screen
--- ### ๐งช Question: *Graph Connectivity via Value Proximity* > Prompt:
Given a sorted array `arr` of size `N`, and an integer `diff`, construct an undirected graph where each node represents an index. Connect nodes `i` and `j` if `|arr[i] - arr[j]| <= diff`. You are given a list of queries `[u, v]`. Return a list of booleans indicating whether there is a path between `u` and `v`. Example: ```python arr = [1, 2, 3, 6] diff = 2 queries = [[0, 2], [1, 3]] Output: [True, False] ``` --- ### โ My Approach: - Since the array is sorted, edges only form between adjacent elements where the difference is within `diff`. - I used Disjoint Set Union (Union-Find) to group connected components efficiently. - For each query, I simply checked if both nodes belonged to the same component. --- ### ๐ง Time & Space: - Build time: O(N)
- Query time: O(Q * ฮฑ(N))
- Space: O(N) --- ### ๐ง Python Code: ```python def are_connected(arr, diff, queries): n = len(arr) parent = list(range(n)) rank = [0] * n def find(u): while parent[u] != u: parent[u] = parent[parent[u]] u = parent[u] return u def union(u, v): ru, rv = find(u), find(v) if ru == rv: return if rank[ru] < rank[rv]: parent[ru] = rv elif rank[ru] > rank[rv]: parent[rv] = ru else: parent[rv] = ru rank[ru] += 1 for i in range(n - 1): if arr[i + 1] - arr[i] <= diff: union(i, i + 1) return [find(u) == find(v) for u, v in queries] ``` --- ### ๐๏ธ Final Thoughts: Even though the round didnโt go through, it was a great experience. The problem tested key concepts in graph theory and DSU. Sharing this to help others preparing for similar interviews! Let me know what went wrong
โ Outcome: Rejected after phone screen
๐ฐ Compensation: unknown
๐ Location: unknown
๐ข Company: Google
๐ Education: unknown
๐ Benefits: unknown
๐ Offer Date: unknown
๐ Company: Google
๐ Round: Phone Screen
๐ง Role: SDE-2
๐๏ธ Experience: 2 YOE
โ Status: Rejected after phone screen
--- ### ๐งช Question: *Graph Connectivity via Value Proximity* > Prompt:
Given a sorted array `arr` of size `N`, and an integer `diff`, construct an undirected graph where each node represents an index. Connect nodes `i` and `j` if `|arr[i] - arr[j]| <= diff`. You are given a list of queries `[u, v]`. Return a list of booleans indicating whether there is a path between `u` and `v`. Example: ```python arr = [1, 2, 3, 6] diff = 2 queries = [[0, 2], [1, 3]] Output: [True, False] ``` --- ### โ My Approach: - Since the array is sorted, edges only form between adjacent elements where the difference is within `diff`. - I used Disjoint Set Union (Union-Find) to group connected components efficiently. - For each query, I simply checked if both nodes belonged to the same component. --- ### ๐ง Time & Space: - Build time: O(N)
- Query time: O(Q * ฮฑ(N))
- Space: O(N) --- ### ๐ง Python Code: ```python def are_connected(arr, diff, queries): n = len(arr) parent = list(range(n)) rank = [0] * n def find(u): while parent[u] != u: parent[u] = parent[parent[u]] u = parent[u] return u def union(u, v): ru, rv = find(u), find(v) if ru == rv: return if rank[ru] < rank[rv]: parent[ru] = rv elif rank[ru] > rank[rv]: parent[rv] = ru else: parent[rv] = ru rank[ru] += 1 for i in range(n - 1): if arr[i + 1] - arr[i] <= diff: union(i, i + 1) return [find(u) == find(v) for u, v in queries] ``` --- ### ๐๏ธ Final Thoughts: Even though the round didnโt go through, it was a great experience. The problem tested key concepts in graph theory and DSU. Sharing this to help others preparing for similar interviews! Let me know what went wrong