Validate matrix symmetric

Last updated: March 16, 2026

Quick Overview

Given a square matrix, write a function to determine if the matrix is symmetric. A matrix is considered symmetric if it is equal to its transpose, meaning that for every element at position (i, j), the element at position (j, i) must be the same. The function should return a boolean value: true if the matrix is symmetric, and false otherwise.

Booking.com
Coding & Algorithms
Machine Learning Engineer
Booking.com
March 16, 2026
Machine Learning Engineer
Phone Screen
Coding & Algorithms
Hard

24

13

163 solved


Given a square matrix, write a function to determine if the matrix is symmetric. A matrix is considered symmetric if it is equal to its transpose, meaning that for every element at position (i, j), the element at position (j, i) must be the same. The function should return a boolean value: true if the matrix is symmetric, and false otherwise.

This coding problem is frequently asked during Phone Screen at Booking.com. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Booking.com expects candidates to write production-quality code, not just solve the puzzle.

What the Interviewer Expects
  • Quickly identify the optimal approach and its theoretical basis
  • Handle complex algorithm design with multiple interacting components
  • Write concise, elegant code under time pressure
  • Prove correctness of your approach and discuss alternative solutions
  • Optimize beyond the obvious: discuss constant factor improvements
  • Address follow-up variations and explain how the solution generalizes
Key Topics to Cover
Dynamic programming and memoization
Time and space complexity analysis
Binary search and divide and conquer
Tree structures and recursion
Hash maps and frequency counting
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
  • What is the worst-case input for your solution?
  • How would your solution change if the input was sorted?
  • What if the input doesn't fit in memory?
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 given square matrix is symmetric, we need to check if the matrix is equal to its transpose. This means that for all indices (i, j), the condition matrix[i][j] == matrix[j][i] must ho...

Approach
  1. Initialize a loop to iterate through the rows of the matrix from 0 to n-1, where n is the size of the matrix.
  2. For each row, initialize another loop to iterate through the columns from 0 ...

Submit Your Answer
Markdown supported

Related Questions