DEV Community

Cover image for Topological sort, Solving Google Interview Question

Topological sort, Solving Google Interview Question

Akhil on June 07, 2020

If we want to become a full-stack developer we follow the following path : First, we learn basic HTML & CSS, then we learn Javascript. Then...
Collapse
 
indefinitelee profile image
Lee Wilson

Small issue: graph[from].add(to); should be .push (to) instead.

but also i am not getting same output as you for that portion of the function, can you specify the parameters you are calling with?
my graph variable shows
[ [ 2, 1 ], [], [ 3, 4 ], [ 6 ], [ 5, 6 ], [], [] ]

Collapse
 
akhilpokle profile image
Akhil

Omg thanks for pointing out, the graph is of another problem I am working on and I miss-matched it.

Graph is :[[2,0],[2,1],[3,2],[4,2],[4,5],[6,3],[6,4]]

I have updated the code :).

Thanks again for pointing out my mistake.

Collapse
 
dalgleish profile image
Andrew

Thanks for publishing this, and maintaining it.

I think the e.g input in the article has a mistake:

[5,4], should be [4,5],

Thread Thread
 
akhilpokle profile image
Akhil

Thanks for reading the article :), and updated my mistake.

Thread Thread
 
_arun_j_ profile image
Arun J

Hi,
Above the second diagram, it is still not corrected

For eg : if give data is [[2,0],[2,1],[3,2],[4,2],[5,4],[6,3],[6,4]]

Collapse
 
petelomax profile image
petelomax

I cannot see where you corrected that but it is still wrong just above step 1.

Thread Thread
 
_arun_j_ profile image
Arun J

For eg : if give data is [2,0],[2,1],[3,2],[4,2],[5,4],[6,3...

Collapse
 
crimsonmed profile image
Médéric Burlet

Nice explanation however i'd like to correct the following:

If we want to become a full-stack developer we follow the following path :

Being full-stack does not mean learning javascript. There are many ways to be full-stack; from .NET to PHP to Ruby to Python.

I would correct to:

If we want to become a full-stack developer we can follow the following path for javascript :
Collapse
 
akhilpokle profile image
Akhil

Noted :)

Collapse
 
ndaidong profile image
Dong Nguyen • Edited

Thank you for your article. You explained as well, however your implementation may have some problems. I didn't run your code but I guess that it will not be able to work as expected. For example:

  • line 20 and line 37, the keyword int
for(int i=0;i<indegree.length;i++){
  • line 35, visited is Set, not Array, so you have to use add(), not push()
visited.push(node);

Please check and fix them :)

Collapse
 
akhilpokle profile image
Akhil

Omg, thanks for pointing out! Code updated :)