988. Count Isolated Nodes in a Graph

EasyGraphsRepresentationGraph

Given an undirected graph with n nodes and a list of edges, return the number of isolated nodes — nodes with degree 0 (no incident edges). The input is JSON {n, edges}.

Input: JSON {n, edges}.

Output: Integer — the number of isolated nodes.

Examples

Example 1
Input: {"n":5,"edges":[[0,1]]}
Output: 3
Explanation: Nodes 2, 3, 4 are isolated.
Example 2
Input: {"n":3,"edges":[]}
Output: 3
Explanation: No edges at all.
Example 3
Input: {"n":2,"edges":[[0,1]]}
Output: 0
Explanation: Both have an edge.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →