NeetCode

In a coding interview, graphs can be given in many different formats. You might not even be told that the input is a graph.

Here are four most common graph representations in coding interviews โฌ‡๏ธ


๐Ÿญ. ๐—”๐—ฑ๐—ท๐—ฎ๐—ฐ๐—ฒ๐—ป๐—ฐ๐˜† ๐— ๐—ฎ๐˜๐—ฟ๐—ถ๐˜… - An n x n 2D matrix where the value in each square denotes whether there exists an edge between two vertices.


๐Ÿฎ. ๐— ๐—ฎ๐˜๐—ฟ๐—ถ๐˜… - A more subtle but common format where each square represents a vertex. The problem statement will tell you how these vertices are connected.


๐Ÿฏ. ๐—”๐—ฟ๐—ฟ๐—ฎ๐˜† ๐—ผ๐—ณ ๐—˜๐—ฑ๐—ด๐—ฒ๐˜€ - You will be given a 2D array and each element will contain a pair of vertices that have an edge connecting them. They appear in [v1,v2] format, meaning there is an edge going from v1 to v2.


๐Ÿฐ. ๐—”๐—ฑ๐—ท๐—ฎ๐—ฐ๐—ฒ๐—ป๐—ฐ๐˜† ๐—Ÿ๐—ถ๐˜€๐˜ - The most convenient format, typically implemented with a hashmap. The key represents a vertex and the value represents the list of its neighbors.

โ€”

Preparing for coding interviews? Check out neetcode.io/

9 months ago | [YT] | 1,825



@programminglite162

Thanks man. Really appreciate you.

9 months ago | 6

@์˜ค๋ž€์’ธ

์ข‹์•„

9 months ago | 0

@Dipak2323

Hey! Thank you for these kinda posts. They really help. However Youtube app doesn't allow me to save these posts for later or download them. If possible, can you please these in YouTube shorts format?

9 months ago | 4

@omaidkhan6398

just want to ask one thing do we really need to put this much effort if AI taking over the software engineering or I am may be taken away by this fear mongering that most youtuber spread. Please anyone who has valid points๐Ÿ™

9 months ago | 2