FastPrepCount the Number of Complete Components
Problems/Count the Number of Complete Components

Count the Number of Complete Components

Amazon logoAmazon● MediumNEW GRADPHONE SCREEN
QuestionFunctionExamples

Problem statement

Source note: The judged task matches the named standard complete-components problem at about 99%. The statement supplies a portable function interface.

You are given an integer n and an undirected graph whose vertices are numbered from 0 through n - 1. The array edges contains each undirected edge [u, v].

A connected component is complete when every pair of distinct vertices in that component is joined by an edge.

Return the number of complete connected components. A component containing one vertex is complete.

Function

countCompleteComponents(n: int, edges: int[][]) → int

Examples

Example 1

n = 6edges = [[0,1],[0,2],[1,2],[3,4]]return = 3

The components are {0,1,2}, {3,4}, and {5}. Each contains every possible internal edge, so all three are complete.

Example 2

n = 6edges = [[0,1],[0,2],[1,2],[3,4],[3,5]]return = 1

The component {0,1,2} is complete. The component {3,4,5} is missing edge [4,5], so it is not complete.

Example 3

n = 1edges = []return = 1

The only vertex forms a one-vertex complete component.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public int countCompleteComponents(int n, int[][] edges) {
      // write your code here
    }
}
Checking account…