To the Top
File:  root - text - article - 2019 - 11 - course.txt
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Category: Computing | 1422 Views, 14165 Search Bots | 159 Words

Subscribe to Feed Burner | Browse | Archive
Hi, here's your problem today. This problem was recently asked by Google:

By the way, check out our NEW project AlgoPro (http://algopro.com) for over 60+ video coding sessions with ex-Google/ex-Facebook engineers.

You are given a hash table where the key is a course code, and the value is a list of all the course codes that are prerequisites for the key. Return a valid ordering in which we can complete the courses. If no such ordering exists, return NULL.

Example:

{
'CSC300': ['CSC100', 'CSC200'],
'CSC200': ['CSC100'],
'CSC100': []
}


This input should return the order that we need to take these courses:
['CSC100', 'CSC200', 'CSCS300']

Here's your starting point:


def courses_to_take(course_to_prereqs):
# Fill this in.

courses = {
'CSC300': ['CSC100', 'CSC200'],
'CSC200': ['CSC100'],
'CSC100': []
}

print courses_to_take(courses)
# ['CSC100', 'CSC200', 'CSC300']
Tags: 每日算法题, 算法, 数据结构, 面试题, Daily Interview Problem, Data Structures and Algorithms, Computer Programming, Python, | English | Home Page | Cateogry: Computing | 1422 Views, 14165 Search Bots | 159 Words Subscribe to Feed Burner

Related Articles

  1. Daily Interview Problem: Deepest Node in a Binary Tree
  2. Daily Interview Question: Create a Simple Calculator
  3. [Daily Problem] Course Prerequisites
  4. Spectrum Master
  5. [Daily Problem] Angles of a Clock
  6. Reverse a Directed Graph
  7. [Daily Problem] Add two numbers as a linked list
  8. Top K Frequent words
  9. Non-decreasing Array with Single Modification
  10. Daily Interview Problem: Merge List Of Number Into Ranges

Comments (0)

    Be the first one to comment this page !


Page Edited: May 11 2024 14:36:49 | RSS Subscription
How to Cook a Perfect Steak? | <meta name="robots" content="index, follow">