987. Find All Neighbours of a Node

EasyGraphsRepresentationGraph

Given an undirected graph with n nodes and a list of edges, return the sorted list of all neighbors of a given node. The input is JSON {n, edges, node}.

Input: JSON {n, edges, node}.

Output: Array — the sorted neighbors of the node.

Examples

Example 1
Input: {"n":5,"edges":[[0,1],[0,2],[1,3]],"node":0}
Output: [1,2]
Explanation: Node 0's neighbors.
Example 2
Input: {"n":3,"edges":[],"node":1}
Output: []
Explanation: Isolated node.
Example 3
Input: {"n":2,"edges":[[0,1]],"node":1}
Output: [0]
Explanation: One neighbor.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →