Validate graph sorted

Last updated: August 9, 2025

Quick Overview

Given a list of integers representing a graph's nodes, write a function to determine if the graph is sorted in non-decreasing order based on the values of its nodes. The function should return a boolean value: true if the graph is sorted, and false otherwise. Consider edge cases such as empty graphs and graphs with a single node.

Expedia
Coding & Algorithms
Software Engineer
Expedia
August 9, 2025
Software Engineer
Technical Screen
Coding & Algorithms
Hard

202

14

580 solved


Given a list of integers representing a graph's nodes, write a function to determine if the graph is sorted in non-decreasing order based on the values of its nodes. The function should return a boolean value: true if the graph is sorted, and false otherwise. Consider edge cases such as empty graphs and graphs with a single node.

Expedia uses this problem in the Technical Screen 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
  • 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
Time and space complexity analysis
Hash maps and frequency counting
Tree structures and recursion
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 test this solution thoroughly?
  • What happens if the input contains duplicates?
  • How would you parallelize this solution?
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 the given list of integers representing the graph's nodes is sorted in non-decreasing order, we can utilize a simple linear scan approach. This problem can be analyzed using a single p...

Approach

The algorithm can be implemented as follows:

  1. Edge Cases: First, handle edge cases: if the list is empty or contains only one node, return true as it is trivially sorted.
  2. **Iterate Through ...

Submit Your Answer
Markdown supported

Related Questions