Validate graph complete

Last updated: September 2, 2025

Quick Overview

Given an undirected graph represented as an adjacency list, write a function to determine if the graph is complete. A complete graph is one in which every pair of distinct vertices is connected by a unique edge. The function should return true if the graph is complete and false otherwise.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
September 2, 2025
Software Engineer
Onsite
Coding & Algorithms
Medium

6

4

4,679 solved


Given an undirected graph represented as an adjacency list, write a function to determine if the graph is complete. A complete graph is one in which every pair of distinct vertices is connected by a unique edge. The function should return true if the graph is complete and false otherwise.

Coding interviews at Microsoft focus on problem-solving approach as much as the final solution. The interviewer wants to see you break down the problem, consider edge cases, and optimize iteratively. Communication throughout the process is key.

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
Hash maps and frequency counting
Sorting and searching
Tree structures and recursion
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
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 your solution change if the input was sorted?
  • Can you optimize the space complexity of your solution?
  • How would you parallelize this solution?
  • Can you solve this iteratively instead of recursively (or vice versa)?
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 complete, we need to check if every pair of distinct vertices has a unique edge connecting them. This means that for an undirected graph with n vertices, there should be e...

Approach
  1. Count Vertices: First, determine the number of vertices n in the graph from the adjacency list.
  2. Count Edges: Initialize a counter for edges and iterate through each vertex's adjacency...

Submit Your Answer
Markdown supported

Related Questions