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

Programming Exercises

Implement a class to represent an undirected graph using a hash where keys are nodes and values are arrays of connected nodes.

Hard

Problem Statement

Implement a class to represent an undirected graph using a hash where keys are nodes and values are arrays of connected nodes.

Sample Input

g = Graph.new; g.add_edge('A', 'B')

Sample Output

{"A"=>["B", "C"], "B"=>["A"], "C"=>["A"]}
true
false

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
class Graph def initialize # Your code here end end
Log in or sign up to run or submit your code.Log inSign up
Input
g = Graph.new; g.add_edge('A', 'B')
Expected Output
{"A"=>["B", "C"], "B"=>["A"], "C"=>["A"]}
true
false