Validate graph symmetric

Last updated: November 23, 2025

Quick Overview

Given an undirected graph represented as an adjacency matrix, write a function to determine if the graph is symmetric. The function should return `true` if the graph is symmetric (i.e., for every edge from vertex A to vertex B, there is an edge from vertex B to vertex A) and `false` otherwise. The input will be a square matrix of size n x n, where n is the number of vertices in the graph.

Redfin
Coding & Algorithms
Software Engineer
Redfin
November 23, 2025
Software Engineer
Take-home Project
Coding & Algorithms
Medium

453

8

645 solved


Given an undirected graph represented as an adjacency matrix, write a function to determine if the graph is symmetric. The function should return `true` if the graph is symmetric (i.e., for every edge from vertex A to vertex B, there is an edge from vertex B to vertex A) and `false` otherwise. The input will be a square matrix of size n x n, where n is the number of vertices in the graph.

Redfin uses this problem in the Take-home Project 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
Binary search and divide and conquer
Data structure selection and trade-offs
Edge cases and input validation
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
  • How would you parallelize this solution?
  • Can you optimize the space complexity of your solution?
  • What if the input doesn't fit in memory?
  • How would you test this solution thoroughly?
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

The problem requires us to check whether an undirected graph is symmetric based on its adjacency matrix representation. A graph is symmetric if for every edge from vertex A to vertex B, there exists a...

Approach
  1. Input Validation: First, check if the input is a square matrix (n x n). If not, return false.
  2. Matrix Comparison: Use a nested loop to iterate through the upper triangle of the matrix (...

Submit Your Answer
Markdown supported

Related Questions