Challenge: Remove Edge
In this challenge, we will learn how to delete an edge between two vertices.
We'll cover the following
Problem Statement
You must implement the removeEdge
function which takes a source and a destination as arguments. If an edge exists between the two, it should be deleted.
Input
A graph, a source (integer), and a destination (integer).
Output
A graph with the edge between the source and the destination removed.
Sample Input
Vertex | Edges |
---|---|
0 | 1, 2 |
1 | 3 |
2 | 3, 4 |
3 | None |
4 | 0 |
Sample Output
removeEdge(graph, 2, 3)
Vertex | Edges |
---|---|
0 | 1, 2 |
1 | 3 |
2 | 4 |
3 | None |
4 | 0 |
Coding Exercise
Take some time to flesh out the logic of your algorithm before moving on to the implementation. You have the previously implemented EduLinkedList
class functions available for use.
Good luck!
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.