Interview Question Directed Graph — Doubt

Правка en1, от Dsxv, 2020-11-19 12:50:31

Hi Everyone!

I haven't been active lately because of interviews going on. Recently I appeared for Amazon Interview for Internship and there was a problem that I still have doubts with:

Problem

As you can see the graph is not an unweighted DAG, Hence, the problem became finding acyclic longest chain in a directed cyclic graph.

I wasn't able to come with a clear solution (O(n)) because it didn't feel right that how I can take care of cases with a cycle using maybe topological sort? So I wanted to ask what is the best possible complexity answer for this.

Thanks!

Теги #graph, directed graph, #interviews

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en4 Английский Dsxv 2020-12-01 17:02:05 40 Tiny change: ' this.\n\n' -> ' this.\n\n**UPD2:** Got selected anyway lol :p\n\n'
en3 Английский Dsxv 2020-11-19 15:33:30 230 Tiny change: ' words as mentioned, not that' -> ' words as by the interviewer, not that'
en2 Английский Dsxv 2020-11-19 14:30:47 239
en1 Английский Dsxv 2020-11-19 12:50:31 892 Initial revision (published)