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

Stripe 電面分享

全局:

2019(7-9月) 码农类General 硕士 全职@stripe - 猎头 - 技术电面  | | WaitList | 在职跳槽

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

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

x
Stripe Tech Phone interview.
  1. # For this interview, imagine that we are working with a simple database. Each row
  2. # associates column names (strings) with integer values (for example: 5, 0, -3,
  3. # and so on). Here's a table with three rows:

  4. # a b c d
  5. # ---------------
  6. # 1 0 0 0
  7. # 0 2 3 0
  8. # 0 0 0 4

  9. # We can choose to represent a database table in JSON as an array of objects. For
  10. # example, the previous table could be written as:

  11. # [ {"a": 1, "b": 0, "c": 0, "d": 0},
  12. # {"a": 0, "b": 2, "c": 3, "d": 0},
  13. # {"a": 0, "b": 0, "c": 0, "d": 4} ]

  14. # (There is no need to use JSON in your solutions -- the notation is just used to
  15. # introduce and explain the problems.)

  16. # Write a function minByColumn that takes a database table (as above), along with a
  17. # column, and returns the row that contains the minimum value for the given column.
  18. # If a row doesn't have any value for the column, it should behave as though the
  19. # value for that column was zero.

  20. # In addition to writing this function, you should use tests to demonstrate that it's
  21. # correct, either via an existing testing system or one you create.
  22. ## Examples

  23. # table1 = [
  24. # {"a": 1},
  25. # {"a": 2},
  26. # {"a": 3}
  27. # ]
  28. # minByColumn(table1, "a") returns {"a": 1}

  29. # In part 1 you may have noticed that it's possible for two rows to be "tied",
  30. # meaning that either would be an acceptable return value from minByColumn.
  31. # Consider:

  32. # table4 = [
  33. # {"a": 1, "b": 2},
  34. # {"a": 1, "b": 3},
  35. # {"a": 1, "b": 4}
  36. # ]
  37. # minByColumn(table4, "a") returns ???

  38. # Since all three rows have the same value for a, all three rows are acceptable
  39. # candidates to be returned by minByColumn(table, "a").

  40. # In these cases it would be nice if users could specify additional columns (e.g. "b")
  41. # to use as tie-breakers. A tie-breaker would only apply in cases where multiple rows
  42. # share the same minimum value. In `table4` above, the row {"a": 1, "b": 2} is
  43. # tied for the smallest "a" value (1) and of all the tied candidates, it has the
  44. # smallest "b" value (2). If two records had equal values for "a" and also for "b" then
  45. # another tie-breaker (e.g. "c") could be used. When records are tied with respect to
  46. # all columns, either record may be considered the minimum.

  47. # Write a function minByOrder that takes a database table and a list of columns, and
  48. # returns the row with the minimum column values using the tie-breaking logic above.
  49. # If only one column is provided, then the behavior of minByOrder is identical to
  50. # passing that column to minByColumn:

  51. # minByOrder(table, [column]) is equal to minByColumn(table, column)

  52. # As in Part 1, you should use tests to demonstrate that it's correct, either via an
  53. # existing testing system or one you create.

  54. # ## Examples
  55. # table5 = [
  56. #   {"x": 1, "y": 3},
  57. #   {"x": 1, "y": 0}
  58. # ]
复制代码



面試時傻了,沒仔細想清楚這題目的真正問題。直接硬上寫了很多方程式
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
面分享我的解法


  1. import sys

  2. def getValue(item, key):
  3.   # since we find the smallest one,
  4.   # default to sys max int if there is no key is provided in the item (column).
  5.   return item.get(key, sys.maxint)

  6. def minByColumn(table, column):
  7.   return sorted(table, key=lambda i: getValue(i, column))[0]

  8. def minByOrder(table, columns):
  9.   return sorted(table, key=lambda i: tuple([getValue(i, c) for c in columns]))[0]

复制代码


歡迎大家不吝嗇指教



评分

参与人数 8大米 +40 收起 理由
tobebeyond + 3 给你点个赞!
wsc_go + 1 给你点个赞!
Ccqw12 + 1 给你点个赞!
joyyy + 1 很有用的信息!
燃烧的猪肉卷 + 2 很有用的信息!

查看全部评分


上一篇:二西格玛 OA
下一篇:钉兴趣安塞过
🔗
wxr.dal 2019-8-11 06:18:01 | 只看该作者
本楼:
全局:
lz过了么
回复

使用道具 举报

🔗
saraggg 2019-8-30 12:55:09 | 只看该作者
全局:
请问楼主面的是哪个职位呀?
回复

使用道具 举报

全局:
楼主过了么
回复

使用道具 举报

🔗
不吃糖 2019-9-5 11:26:50 | 只看该作者
全局:
这题地里之前没有哎
回复

使用道具 举报

🔗
jnyt989 2019-9-5 22:55:28 | 只看该作者
全局:
求问楼主OA后多久的电面呀
回复

使用道具 举报

🔗
Jimmy123 2020-3-14 10:52:25 | 只看该作者
全局:
minByColumn 只需要o(n) 扫一遍,看min就好了,不需要sort o(nlogn)把
回复

使用道具 举报

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

本版积分规则

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