Embercode
✕
GraphsQuick quiz

Ordering tasks and words

8 questions. Covers Course schedule and alien dictionary.

Questions 1 to 5 of 8

  1. 1. Put the steps of the course schedule method (findOrder) in the order the lesson gives them.

    Use the arrows to put the steps in order.

    1. 1.Take the front course, add it to the order, and lower the waiting count of each course it unlocks
    2. 2.When the queue is empty, compare the order's length with the number of courses
    3. 3.Put every course with a waiting count of 0 into a queue
    4. 4.Count each course's prerequisites as its waiting count
  2. 2. Put the steps of alienOrder in the order the lesson gives them.

    Use the arrows to put the steps in order.

    1. 1.Compare each pair of neighbouring words and add an edge at the first differing letter
    2. 2.Put every letter with a waiting count of 0 into a sorted set
    3. 3.Take the smallest letter from the set, add it to the answer, and lower the counts of the letters it unlocks
    4. 4.Register every letter that appears in any word
  3. 3. What does alienOrder return for the words abc then ab?
  4. 4. In alienOrder, what does .second from unlocks[a[j]].insert(b[j]) tell the code?
  5. 5. What does this program print? ``cpp #include <iostream> #include <set> int main() { std::set<char> unlocks; int waitingFor = 0; for (char ch : {'t', 'f', 't'}) { if (unlocks.insert(ch).second) ++waitingFor; } std::cout << "waiting " << waitingFor << ", unlocks " << unlocks.size() << '\n'; } ``

3 question(s) left on this page.