Please change the input format

  • 4

    Using vector of vector should imply a adjacency list/matrix representation of the prereq graph. If you want to represent the graph simply as a collection of edges, you should use vector<pair<int, int> > instead. Such ill-formatted input with insufficient specification is time-wasting and should be discouraged in industry, and in interviews.

  • -3

    Java does not have pair. I decided to use vector<int> to keep a consistent format among all languages.

    Also I think pair is no better in my opinion. What does it mean by pair.first or pair.second? It does not mean anything. It is better to define your own class for the highest clarity.


    Thanks for the down votes, it seems like the community also feel that the problem description could be better.

    Thanks to @will5 feedback, it is such feedback that will improve the quality of the problem description. I've moved point no. 2. from hints section to the problem specification. I hope it is now clear enough to the users to avoid assuming that the input graph is represented as adjacency matrices.

    The input type is also changed from vector<vector<int>> to vector<pair<int, int>> for maximum clarity.

  • 0

    hey, buddy, please don't take it as I was criticizing you or anything. I was merely stating facts and making suggestions.

    First of all, I do appreciate you sharing the problem and the test cases. It's a classic application of toposort, and for an oj like leetcode with a limited amount of problems, it will definitely benefit from the addition of your problem.

    However, i have to humbly disagree most of your points above.

    If your sole purpose of using vector<int> to represent a single edge is to keep the consistency with the Java signature, why not simply use adjacency list/matrix representation for both Java and C++?

    I agree with you that its best to define your own Edge class, but since I take it your argument is that you can't afford to do that on leetcode, pair is surely much less confusing than vec of int in that it enforces the number of values to match the number of endpoints of an edge, i.e. 2.

    if you insist on using a vec of int to represent a single edge, the least you could do is to move hint 2 to problem statement, without the "for example" or the trailing question. Undoubtedly it should be part of the problem specification, not a hint.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.