📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 5
跳转到指定楼层
上一主题 下一主题
收起左侧

Duolingo Intern Karat

🔗
匿名用户-SZIIM  2022-9-21 11:40:50 |倒序浏览

2022(7-9月) 码农类General 本科 实习@duolingo - 网上海投 - 视频面试  | 😐 Neutral 😣 Hard | WaitList | 应届毕业生

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

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

x
/*

You are going on a camping trip.

You and your friends are planning the hike to your campsite but there are various attractions you would like to see along the way. You are trying to plan a route where you can see all of your desired attractions without walking the same trail twice.

Trails are listed by the attractions they connect, all trails are 2-way trails and there can be multiple trails between 2 places.

Given a list of trails and a list of desired attractions, return whether there is a path which starts at the Parking Lot and ends at the Campsite which visits all of the desired attractions without using the same trail twice.
===============================================================
Examples:
===============================================================

Liberty Lake    Frozen Ocean   Eel Weir
    |            |        |    |      |
Parking Lot------Beaver Dam----Campsite

trails1 = [
    ["Beaver Dam",  "Frozen Ocean"], # First trail between Beaver Dam/Frozen Ocean
    ["Beaver Dam",  "Frozen Ocean"], # Second trail between Beaver Dam/Frozen Ocean
    ["Parking Lot", "Beaver Dam"],
    ["Parking Lot", "Liberty Lake"],
    ["Beaver Dam",  "Campsite"],
    ["Eel Weir",  "Campsite"],
    ["Eel Weir",  "Campsite"],
]
attractions1_1 = ["Frozen Ocean"] => True
Path: Parking Lot->Beaver Dam->Frozen Ocean->Beaver Dam->Campsite

attractions1_2 = ["Liberty Lake", "Beaver Dam"] => False
It is not possible to return from Liberty Lake so this path is not possible.

attractions1_3 = ["Eel Weir"] => True
Path: Parking Lot->Beaver Dam->Campsite->Eel Weir->Campsite
--------------------------------------------
                Liberty Lake
                |    |    |
Jeremy's Bay--Mason's Cabin--Parking Lot
      |                        |     
    Horseshoe Falls----Mills Falls----Eel Weir--Outdoor Theater--Campsite
                                             \                   /
                                              --Hardwood Forest--
trails2 = [
    ["Mason's Cabin", "Liberty Lake"],
    ["Parking Lot", "Mill Falls"],
    ["Mason's Cabin", "Jeremy's Bay"],
    ["Eel Weir", "Hardwood Forest"],
    ["Outdoor Theater", "Campsite"],
    ["Jeremy's Bay", "Horseshoe Falls"],
    ["Mason's Cabin", "Parking Lot"],
    ["Mason's Cabin", "Liberty Lake"],
    ["Mill Falls", "Horseshoe Falls"],
    ["Mill Falls", "Eel Weir"],
    ["Hardwood Forest", "Campsite"],
    ["Eel Weir", "Outdoor Theater"],
    ["Liberty Lake", "Mason's Cabin"]
]
attractions2_1 = ["Jeremy's Bay", "Mason's Cabin", "Outdoor Theater"] #=> True
attractions2_2 = ["Outdoor Theater", "Eel Weir", "Hardwood Forest"] #=> False
attractions2_3 = ["Liberty Lake"] #=> True
attractions2_4 = ["Horseshoe Falls", "Eel Weir"] #=> True

All Test Cases:
sightseeing(trails1, attractions1_1) => True
sightseeing(trails1, attractions1_2) => False
sightseeing(trails1, attractions1_3) => True
sightseeing(trails2, attractions2_1) => True
sightseeing(trails2, attractions2_2) => False
sightseeing(trails2, attractions2_3) => True
sightseeing(trails2, attractions2_4) => True

Complexity Variable:
n = number of trails


*/

丑陋的代码还请大家指出有没有更好的做法qwq

您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies


补充内容 (2022-09-23 05:48 +8:00):
收到终面邀请 ⚽️⚽️duolingo了,孩子到现在还没上岸

评分

参与人数 3大米 +22 收起 理由
匿名用户-687RN + 20
digAccount + 1 很有用的信息!
6194 + 1 赞一个

查看全部评分


上一篇:23NG给亚麻SP发邮件催收到了回复
下一篇:mata london MLE: failed
地里匿名用户
🔗
匿名用户-B0TBD  2022-9-21 23:31:26
请问attractions2_1要怎么走啊?
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-SZIIM  2022-9-22 00:14:10
匿名用户 发表于 2022-9-21 11:31
请问attractions2_1要怎么走啊?

从parking lot出发从左边绕一圈,因为不要求先后顺序访问
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-67ZFV  2022-11-13 10:33:55
请问这个解法是有错误吗。。为什么划掉了
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-SZIIM  2022-11-13 10:42:38
匿名用户 发表于 2022-11-12 21:33
请问这个解法是有错误吗。。为什么划掉了

没有,只是系统帮我搞的
回复

使用道具 举报

地里匿名用户
🔗
匿名用户-67ZFV  2022-11-14 11:53:57
匿名用户 发表于 2022-11-12 18:42
没有,只是系统帮我搞的

kk, 请问这个时间复杂度怎么分析呢,感觉还挺复杂
回复

使用道具 举报

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

本版积分规则

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