No need to build the sorted order

Since the problem requires only to check if all tasks can be executed (ie. return type is bool), the vector<int> sortedOrder is not necessary. The count can be tracked in a simple int sortedOrder = 0. Instead of sortedOrder.push_back(vertex), you do ++sortedOrder, and then at the end return sortedOrder == tasks.

Note: this comment refers to the C++ provided solution.

1 Like

Hi @Claudiu!

You are saying that “the problem requires only to check if all tasks can be executed (ie. return type is bool ),” but the lesson says " Given a sequence originalSeq and an array of sequences, write a method to find if originalSeq can be uniquely reconstructed from the array of sequences." Since each sequence in the given array defines the ordering of some numbers, we need to combine all these ordering.

You can check this for reference and the explanation given below.

After this, if you have any queries, reply here.

Hello @Rabia_Mumtaz, I think you are talking about another task. My comment is for Tasks Scheduling (medium), for which you need to implement the function that has the following signature:

static bool isSchedulingPossible(int tasks, const vector<vector<int>>& prerequisites);

1 Like

@Claudiu, you are right. We don’t need a vector. The previous and the next problem require returning the order of the task, but ‘Task Schecduling’ can be done with simple counting.


Hi @Claudiu

I apologize for the late reply.

The method you are saying is probably the alternative to this code that we have given in the course. One problem can be solved in many different ways. Maybe there are any 3rd and 4th and more codes to do the same.

I checked and find there is no issue with our prescribed code method.