<
回复: 8
收起左侧

Stripe最新店面

匿名用户-YCTCU  2021-12-17 02:23:27
本楼:   👍  2
100%
0%
0   👎

2021(10-12月) 码农类General 硕士 全职@stripe - 猎头 - 技术电面  | 😐 Neutral 😐 AverageOther | 在职跳槽

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

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

x
Stripe 店面, 是一个新加坡小哥面的。题目很简单, 考的是逻辑,难度在于在45分钟内全部写完.

/*
Your previous Plain Text content is preserved below:

For the purposes of this interview, imagine that we own a store. This
store doesn't always have customers shopping: there might be some long
stretches of time where no customers enter the store. We've asked our
employees to write simple notes to keep track of when customers are
shopping and when they aren't by simply writing a single letter every
hour: 'Y' if there were customers during that hour, 'N' if the store
was empty during that hour.

For example, our employee might have written "Y Y N Y", which means
the store was open for four hours that day, and it had customers
shopping during every hour but its third one.

  hour: | 1 | 2 | 3 | 4 |
  log:  | Y | Y | N | Y |
                  ^
                  |
            No customers during hour 3

We suspect that we're keeping the store open too long, so we'd like to
understand when we *should have* closed the store. For simplicity's
sake, we'll talk about when to close the store by talking about how
many hours it was open: if our closing time is `2`, that means the
store would have been open for two hours and then closed.

  hour:         | 1 | 2 | 3 | 4 |
  log:          | Y | Y | N | Y |
  closing_time: 0   1   2   3   4
                ^               ^
                |               |
         before hour #1    after hour #4

(A closing time of 0 means we simply wouldn't have opened the store at
all that day.)

First, let's define a "penalty": what we want to know is "how bad
would it be if we had closed the store at a given hour?" For a given
log and a given closing time, we compute our penalty like this:

  +1 penalty for every hour that we're *open* with no customers
  +1 penalty for every hour that we're *closed* when customers would have shopped

For example:

  hour:    | 1 | 2 | 3 | 4 |   penalty = 3:
  log:     | Y | Y | N | Y |     (three hours with customers after closing)
  penalty: | * | * |   | * |
           ^
           |
         closing_time = 0

  hour:    | 1 | 2 | 3 | 4 |   penalty = 2:
  log:     | N | Y | N | Y |      (one hour without customers while open +
  penalty: | * |   |   | * |       one hour with customers after closing)
                   ^
                   |
                 closing_time = 2

  hour:    | 1 | 2 | 3 | 4 |   penalty = 1
  log:     | Y | Y | N | Y |      (one hour without customers while open)
  penalty: |   |   | * |   |
                           ^
                           |
                         closing_time = 4

Note that if we have a log from `n` open hours, the `closing_time`
variable can range from 0, meaning "never even opened", to n, meaning
"open the entire time".

1a)
Write a function `compute_penalty` that computes the total penalty, given
  a store log (as a space separated string) AND
  a closing time (as an integer)

In addition to writing this function, you should use tests to
demonstrate that it's correct. Do some simple testing, and then quickly
describe a few other tests you would write given more time.

## Examples

compute_penalty("Y Y N Y", 0) should return 3
compute_penalty("N Y N Y", 2) should retu
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
|
                         +-----------+
                           valid log

We can extract only one valid sequence, "BEGIN Y Y END". For our
purposes, we should ignore any invalid sequences. *These logs cannot
be nested.*

Write a function `get_best_closing_times` that takes an aggregate log
as a string and returns an array of best closing times for every valid
log we can find, in the order that we find them.

Again, you should use tests to demonstrate that it's correct. Do
some simple testing, and then quickly describe a few other tests
you would write given more time.

## Examples
get_best_closing_times("BEGIN Y Y END \nBEGIN N N END")
  should return an array: [2, 0]
get_best_closing_times("BEGIN BEGIN \nBEGIN N N BEGIN Y Y\n END N N END")
  should return an array: [2]


*/

评分

参与人数 5大米 +19 收起 理由
shanewww + 1 赞一个
cute2333 + 1 很有用的信息!
asyz13jinage + 1 很有用的信息!
清道神君 + 15
不变微笑的弧度 + 1 给你点个赞!

查看全部评分


上一篇:Meta MLE 实习面经
下一篇:问一下move to another job是几成把握啊?

本帖被以下淘专辑推荐:

  • · Stripe|主题: 18, 订阅: 0
niyanwen212 2021-12-22 10:17:37 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   317
99%
1%
3
请问input中 "BEGIN Y Y END \nBEGIN N N END" 有\n 吗?
回复

使用道具 举报

地里匿名用户
匿名用户-YCTCU  2021-12-23 08:30:15
本楼:   👍  0
0%
0%
0   👎
niyanwen212 发表于 2021-12-21 18:17
请问input中 "BEGIN Y Y END \nBEGIN N N END" 有\n 吗?

有的 zszszszszs
扫码关注一亩三分地求职移民公众号
更多干货内容等你发现
回复

使用道具 举报

地里匿名用户
匿名用户-LPHYO  2022-1-21 09:24:17
本楼:   👍  0
0%
0%
0   👎
楼主过了吗?三道题目test cases都过了
回复

使用道具 举报

bob2018 2022-1-28 00:42:23 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   23
88%
12%
3
谢谢分享
回复

使用道具 举报

phisixersai1 2022-2-13 16:51:33 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   0
0%
0%
0
感謝分享!!!
回复

使用道具 举报

sapience 2022-2-13 18:01:25 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   1
100%
0%
0
谢谢分享!
回复

使用道具 举报

地里匿名用户
匿名用户-LSB4G  2024-5-23 08:23:46
本楼:   👍  0
0%
0%
0   👎
请问要给出时间空间复杂度吗
回复

使用道具 举报

am42 2024-6-3 09:27:52 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   0
0%
0%
0
谢谢分享
回复

使用道具 举报

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

本版积分规则

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