Count the Number of Complete Components

You are given an integer n (vertices numbered 0 to n - 1) and an array edges of undirected edges. Return the number of connected components that are complete, meaning every pair of vertices inside the component is joined by an edge.

30:00

Count the Number of Complete Components
medium
Free written solution
Topics
Companies

You are given an integer n (vertices numbered 0 to n - 1) and an array edges of undirected edges. Return the number of connected components that are complete, meaning every pair of vertices inside the component is joined by an edge.

Example 1:
Input: {"n":6,"edges":[[0,1],[0,2],[1,2],[3,4]]}
Output: 3
Constraints:
  • 1≤n≤501 \leq n \leq 50

  • 0≤edges.length≤n⋅(n−1)/20 \leq \text{edges.length} \leq n \cdot (n - 1) / 2

  • edges[i].length=2\text{edges}[i].\text{length} = 2

  • 0≤ai,bi≤n−10 \leq a_i, b_i \leq n - 1, ai≠bia_i \neq b_i

  • There are no repeated edges.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":6,"edges":[[0,1],[0,2],[1,2],[3,4]]}

6 vertices and 4 edges. A component is complete when every pair of its vertices is joined directly.

012345

exploring

complete

not complete

unseen

stack

empty

complete so far

0

Variables
VariableValue
count0
DepthFunction Call
Stack empty
0/12