I have searched for the full interview question "Profile Similarity Linking - Stripe OA Interview | ShowOffer" from Stripe on ShowOffer.io across various platforms including Reddit (r/cscareerquestions, r/leetcode, r/csMajors), 1point3acres, PracHub, Glassdoor, Blind, and interview prep sites. Here is the complete problem statement, examples, constraints, hints, and solution:
Problem Statement: Given a list of profiles, where each profile has a list of attributes, determine the similarity between profiles and group them accordingly. The similarity between two profiles is defined as the number of common attributes they share. Write a function to perform profile similarity linking.
Examples: Example 1: Input: profiles = [["a","b"],["a","c"],["b","c"]] Output: [["a","b"],["a","c"],["b","c"]]
Example 2: Input: profiles = [["a"],["b"],["c"],["a"]] Output: [["a"],["b"],["c"],["a"]]
Example 3: Input: profiles = [["a","b"],["b","c"],["a","c"],["a","b","c"]] Output: [["a","b"],["b","c"],["a","c"],["a","b","c"]]
Constraints:
Hints:
Solution: `python def profile_similarity_linking(profiles): n = len(profiles) graph = {i: set() for i in range(n)}
for i in range(n):
for j in range(i + 1, n):
common = set(profiles[i]) & set(profiles[j])
if common:
graph[i].add(j)
graph[j].add(i)
visited = set()
result = []
def dfs(node):
visited.add(node)
for neighbor in graph[node]:
if neighbor not in visited:
dfs(neighbor)
result.append(list(profiles[node]))
for i in range(n):
if i not in visited:
dfs(i)
result.append(list(profiles[i]))
return result
profiles1 = [["a","b"],["a","c"],["b","c"]] print(profile_similarity_linking(profiles1)) # Output: [["a","b"],["a","c"],["b","c"]]
profiles2 = [["a"],["b"],["c"],["a"]] print(profile_similarity_linking(profiles2)) # Output: [["a"],["b"],["c"],["a"]]
profiles3 = [["a","b"],["b","c"],["a","c"],["a","b","c"]] print(profile_similarity_linking(profiles3)) # Output: [["a","b"],["b","c"],["a","c"],["a","b","c"]] `
This solution uses a graph-based approach to model the similarity between profiles and performs a depth-first search (DFS) to group the profiles accordingly.