Validate graph symmetric

Last updated: January 23, 2026

Quick Overview

Given an undirected graph represented as an adjacency list, write a function to determine if the graph is symmetric, meaning that for every edge (u, v), there exists a corresponding edge (v, u). The function should return a boolean value: true if the graph is symmetric, and false otherwise.

Twitter/X
Coding & Algorithms
Software Engineer
Twitter/X
January 23, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

10

2

2,134 solved


Given an undirected graph represented as an adjacency list, write a function to determine if the graph is symmetric, meaning that for every edge (u, v), there exists a corresponding edge (v, u). The function should return a boolean value: true if the graph is symmetric, and false otherwise.

Twitter/X uses this problem in the Onsite to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.

What the Interviewer Expects
  • Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
  • Discuss multiple approaches and trade-offs before coding
  • Implement an optimal solution with clean, production-quality code
  • Handle all edge cases including boundary conditions and invalid input
  • Optimize both time and space complexity with clear justification
  • Test your solution systematically with well-chosen examples
Key Topics to Cover
Dynamic programming and memoization
Time and space complexity analysis
Binary search and divide and conquer
Tree structures and recursion
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
Sorting and searching
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Can you solve this iteratively instead of recursively (or vice versa)?
  • What happens if the input contains duplicates?
  • How would your solution change if the input was sorted?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Problem Analysis

To determine if a graph is symmetric, we need to verify that for every edge (u, v) in the adjacency list, there is a corresponding edge (v, u). This problem can be approached using a graph traversal m...

Approach
  1. Initialize: Create a set to keep track of visited nodes.
  2. Iterate Over Each Node: For each node in the graph, if it hasn't been visited, perform a BFS.
  3. BFS Implementation: During...

Submit Your Answer
Markdown supported

Related Questions