__SAK__'s blog

By __SAK__, history, 2 years ago, In English

You might have seen the problem Course Schedule on Leetcode [https://leetcode.com/problems/course-schedule/] Here the ans just comes down to finding if there exists a cycle in the graph or not. I wanted to find the how many total courses can I take if not all the courses. One approach I thought was a multisource BFS with maintaining the indegree for each node and updating it but it would be quite slow. Can anyone suggest any faster method?

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

By __SAK__, history, 2 years ago, In English

Couldn't come up with a approach to this problem, please suggest some approaches

Specifically, Billy's N kids are tagged with ID numbers 1...N.

Billy wants to take a picture of the kids standing in a line in a very specific ordering, represented by the contents of an array A[1...N], where A[j] gives the ID number of the jth kid in the ordering.

He arranges the kids in this order, but just before he can press the button on his camera to snap the picture, up to one kid moves to a new position in the lineup. More precisely, either no kids move, or one kid vacates her current position in the lineup and then re-inserts herself at a new position in the lineup.

Frustrated but not deterred, Billy again arranges his kids according to the ordering in A, but again, right before he can snap a picture, up to one kid (different from the first) moves to a new position in the lineup.

The process above repeats for a total of five photographs before Billy gives up.

Given the contents of each photograph, see if you can reconstruct the original intended ordering A. Each photograph shows an ordering of the kids in which up to one kid has moved to a new location, starting from the initial ordering in A.

Moreover, if a kid opts to move herself to a new location in one of the photographs, then that kid does not actively move in any of the other photographs (although that kid can end up at a different position due to other kids moving, of course).

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it