回复: 3
跳转到指定楼层
上一主题 下一主题
收起左侧

Amazon2019 OA题一道 完整代码及unit测试

全局:

2019(7-9月) 码农类General 硕士 全职@amazon - 内推 - 在线笔试  | | Other | 应届毕业生

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

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

x
Optimal Utilization<求米求米!一起攒人品哇>

Given 2 lists a and b. Each element is a pair of integers where the first integer represents the unique id and the second integer represents a value. Your task is to find an element from a and an element form b such that the sum of their values is less or equal to target and as close to target as possible. Return a list of ids of selected elements. If no pair is possible, return an empty list.

Example 1:

Input:
a = [[1, 2], [2, 4], [3, 6]]
b = [[1, 2]]
target = 7

Output: [[2, 1]]

Explanation:
There are only three combinations [1, 1], [2, 1], and [3, 1], which have a total sum of 4, 6 and 8, respectively.
Since 6 is the largest sum that does not exceed 7, [2, 1] is the optimal pair.
Example 2:

Input:
a = [[1, 3], [2, 5], [3, 7], [4, 10]]
b = [[1, 2], [2, 3], [3, 4], [4, 5]]
target = 10

Output: [[2, 4], [3, 2]]

Explanation:
There are two pairs possible. Element with id = 2 from the list `a` has a value 5, and element with id = 4 from the list `b` also has a value 5.
Combined, they add up to 10. Similarily, element with id = 3 from `a` has a value 7, and element with id = 2 from `b` has a value 3.
These also add up to 10. Therefore, the optimal pairs are [2, 4] and [3, 2].
Example
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
  res = solver.largestCombination(a, b, target)
        print(res)
        len_res = len(res)
        self.assertEquals(len_res, 1)
        self.assertIn([3, 1], res, "[3,1]")

    def test4(self):
        a = [[1, 8], [2, 15], [3, 9]]
        b = [[1, 8], [2, 11], [3, 12]]
        target = 20
        solver = Combination()
        res = solver.largestCombination(a, b, target)
        print(res)
        len_res = len(res)
        self.assertEquals(len_res, 2)
        self.assertIn([1, 3], res)
        self.assertIn([3, 2], res)



test = MyTest('test1')
test.test1()
test.test2()
test.test3()
test.test4()





评分

参与人数 7大米 +38 收起 理由
mlli + 1 欢迎分享你知道的情况,会给更多积分奖励!
lemonyujia + 1 很有用的信息!
asaimirai2014 + 1 给你点个赞!
Vincent6 + 2 给你点个赞!
匿名用户-HJUPE + 30

查看全部评分


上一篇:Intuit新鲜一轮面经2019/09
下一篇:纯储 on campus 面经
🔗
HasMirror 2019-9-19 04:51:04 | 只看该作者
全局:
求问楼主申请的时间 然后过了多久给的OA啊
回复

使用道具 举报

🔗
悠扬哟 2019-12-22 10:38:32 | 只看该作者
全局:
感谢楼主分享!

评分

参与人数 1大米 +2 收起 理由
Betterman + 2 给你点个赞!

查看全部评分

回复

使用道具 举报

🔗
lsklhw 2022-3-25 02:07:41 | 只看该作者
全局:
不错,学习了
回复

使用道具 举报

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

本版积分规则

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