Z03

User Clusters Community Detection

Staff / Principal Engineer
Target Time: 40 - 50 Minutes
Type: ARRAY

Problem Statement & Objective

Partition a social network graph into densely connected clusters using union-find.

Function Signature (Python)

user_clusters_community_detection(records: list[list[str]]) -> list[int]

Input & Output Contract

Output Rule:Azalan sırada sıralanmış küme boyutları. Boş kayıt listesi için [].

System Constraints

0 <= kayitlar.length <= 10^5
kullanıcı adı ve cihaz kimliği boş olmayan ASCII metinler
AYNI (kullanıcı, cihaz) ikilisi birden fazla kez gelebilir

Example Execution Walkthrough

kayitlar = [["ali","d1"], ["zeynep","d1"], ["mert","d2"], ["can","d2"], ["cem","d3"], ["ali","d3"]]
küme A = {ali, zeynep, cem} boyut 3
küme B = {mert, can} boyut 2
cevap: [3, 2]

Example Test Scenarios (3)

Example 1
Input:[[["ali","d1"],["zeynep","d1"],["mert","d2"],["can","d2"],["cem","d3"],["ali","d3"]]]
Expected Output:[3,2]
Example 2: İki Ayrık Kullanıcı
Input:[[["u1","c1"],["u2","c2"]]]
Expected Output:[1,1]
Example 3: Cihaz Üzerinden Birleşme
Input:[[["u1","c1"],["u1","c2"],["u2","c2"]]]
Expected Output:[2]
Loading Python Editor...
Input Parameters
[
  [
    [
      "ali",
      "d1"
    ],
    [
      "zeynep",
      "d1"
    ],
    [
      "mert",
      "d2"
    ],
    [
      "can",
      "d2"
    ],
    [
      "cem",
      "d3"
    ],
    [
      "ali",
      "d3"
    ]
  ]
]
Expected Output
[
  3,
  2
]