Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Perform depth-first and breadth-first searches on a graph.

Hard

Problem Statement

Perform depth-first and breadth-first searches on a graph.

Sample Input

Graph: 0 -> 1, 2; 1 -> 2; 2 -> 0, 3; 3 -> 3. Start Node: 2

Sample Output

DFS: 2, 0, 1, 3
BFS: 2, 0, 3, 1

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
using System; using System.Collections.Generic; class GraphSearch { static void Main() { // Perform DFS and BFS on the graph } }
Log in or sign up to run or submit your code.Log inSign up
Input
Graph: 0 -> 1, 2; 1 -> 2; 2 -> 0, 3; 3 -> 3. Start Node: 2
Expected Output
DFS: 2, 0, 1, 3
BFS: 2, 0, 3, 1