注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
New Grad 202 Stripe电面第一轮
# Part 1
# For this interview, imagine that we are working with a simple database. Each row
# associates column names (strings) with integer values (for example: 5, 0, -3,
# and so on). Here's a table with three rows:
# a b c d
# ---------------
# 1 0 0 0
# 0 2 3 4
# 0 0 0 4
# We can choose to represent a database table in JSON as an array of objects. For
# example, the previous table could be written as:
# [ {"a": 1, "b": 0, "c": 0, "d": 0},
# {"a": 0, "b": 2, "c": 3, "d": 0},
# {"a": 0, "b": 0, "c": 0, "d": 4} ]
# (There is no need to use JSON in your solutions -- the notation is just used to
# introduce and explain the problems.)
# Write a function minByColumn that takes a database table (as above), along with a
# column, and returns the row that contains the minimum value for the given column.
# If a row doesn't have any value for the column, your function should behave as
# though the value for that column was zero.
# In ["x", "y"]) returns {"x": 1, "y": 10}
# table7 = [
# {"x": 3, "y": -1, "z": 0},
# {"x": 1, "y": 10, "z": 1},
# {"x": 1, "y": 10, "z": 0}
# ]
# minByOrder(table7, ["x", "y", "z"]) returns {"x": 1, "y": 10, "z": 0}
# table8 = [
# {"x": 1, "y": 2, "z": 3},
# {"x": 2, "y": 2, "z": 2}
# ]
# minByOrder(table8, ["x", "y", "z"]) returns {"x": 1, "y": 2, "z": 3}
希望可以帮到大家 也祝我好运🍀
|