查看: 1462| 回复: 2
跳转到指定楼层
上一主题 下一主题
收起左侧

[树/链表/图] Robinhood面经里的一题没有思路

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
参考:https://www.1point3acres.com/bbs/thread-739042-1-1.html第一问基本上就是LC上的course schedule,第二问应该怎么做?


第一问:

一堆课,找出上课顺序里,中间的那门课,只有一种正确的顺序,并且每个课只会对应另外一个prereq
比如

    ["Data Structures", "Algorithms"],
    ["COBOL", "Networking"],
    ["Algorithms", "COBOL"],

"Data Structures"->"Algorithms" -> "COBOL"-> "Networking"

返回 “Algorithms"


第二问:

/*
有多种track,返回所有path里的中间那门课

Sample input 1:
all_courses_1 = [
    ["Logic", "COBOL"],
    ["Data Structures", "Algorithms"],
    ["Creative Writing", "Data Structures"],
    ["Algorithms", "COBOL"],
    ["Intro to Computer Science", "Data Structures"],
    ["Logic", "Compilers"],
    ["Data Structures", "Logic"],
    ["Graphics", "Networking"],
    ["Networking", "Algorithms"],
    ["Creative Writing", "System Administration"],
    ["Databases", "System Administration"],
    ["Creative Writing", "Databases"],
    ["Intro to Computer Science", "Graphics"],
]

Sample output 1 (in any order):
          ["Data Structures", "Networking", "Creative Writing", "Databases"]

All paths through the curriculum (midpoint *highlighted*):

Intro to C.S. -> Graphics -> *Networking* -> Algorithms -> Cobol
Intro to C.S. -> *Data Structures* -> Algorithms -> COBOL
Intro to C.S. -> *Data Structures* -> Logic -> COBOL
Intro to C.S. -> *Data Structures* -> Logic -> Compiler
Creative Writing -> *Databases* -> System Administration
*Creative Writing* -> System Administration
Creative Writing -> *Data Structures* -> Algorithms -> COBOL
Creative Writing -> *Data Structures* -> Logic -> COBOL
Creative Writing -> *Data Structures* -> Logic -> Compilers

Visual representation:

                    ____________    ______________
                    |          |    |            |
                    | Graphics |    | Networking |
               ---->|__________|--->|____________|
               |                       |      
               |                       |      
               |                       |  ______________
____________   |                       |  |            |
|          |   |    ______________     >->| Algorithms |--\     _____________
| Intro to |   |    |            |    /   |____________|   \    |           |
| C.S.     |---+    | Data       |   /                      >-->| COBOL     |
|__________|    \   | Structures |--+     ______________   /    |___________|
                 >->|____________|   \    |            |  /
____________    /                     \-->| Logic      |-+      _____________
|          |   /    ______________        |____________|  \     |           |
| Creative |  /     |            |                         \--->| Compilers |
| Writing  |-+----->| Databases  |                              |___________|
|__________|  \     |____________|-\     _________________________
               \                    \    |                       |
                \--------------------+-->| System Administration |
                                         |_______________________|

Sample input 2:
all_courses_2 = [
    ["Course_3", "Course_7"],
    ["Course_0", "Course_1"],
    ["Course_1", "Course_2"],
    ["Course_2", "Course_3"],
    ["Course_3", "Course_4"],
    ["Course_4", "Course_5"],
    ["Course_5", "Course_6"],
]
Sample output 2 (in any order):
["Course_2", "Course_3"]

Complexity analysis variables:

n: number of pairs in the input

*/

评分

参与人数 1大米 +10 收起 理由
14417335 + 10

查看全部评分


上一篇:也来分享我的Notion刷题记录,总结归纳为导向,而不是计划导向
下一篇:leetcode 刷的上火
全局:
天啦噜 最近刚面了这道题 我只给面试官降了一下思路 代码没有写完

可以用graph的结构,每门课是一个点,课之间的dependency可以认为是edge。所以如果计算出所有可能的第一门课,和所有可能的最后一门课,然后算出所有可能的路径,就可以得到所有可能的中间课了。

请问下lz面经在哪里看啊
回复

使用道具 举报

🔗
wisdompeak2 2021-6-11 16:55:38 | 只看该作者
全局:
看一下LC310.

评分

参与人数 3大米 +7 收起 理由
GuoJSeven + 3 很有用的信息!
jliu + 3 很有用的信息!
14417335 + 1

查看全部评分

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表