Hi Njud,
I understand that you need to label your graph as per the below stated conditions:
- Value for the adjacent nodes should differ by at least 2.
- Value for nodes with distance 2, should differ by 1.
To do so, you will have to use recursion or stack for implementing a graph traversal algorithm(BFS should be of help).
Please refer to the following documentation of “bfsearch”, which is an in-built function for BFS,
Hope this helps!
Best Regards,
Aryan Gupta