📣 独立日限时特惠: VIP通行证立减$68
回复: 1
跳转到指定楼层
上一主题 下一主题
收起左侧

亚麻社招OA 和代码

全局:

2017(7-9月) 码农类General 硕士 全职@amazon - 猎头 - 在线笔试  | | Other | 在职跳槽

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

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

x
社招刚做的OA, 两道题,1. 有一个仓库,然后找距离0,0最近的K个点
2. 给一个整数数组,先建立bst,不需要rebalance,给两个点,求这两个点在树中的距离。

本版看面经OA的时候,看到另外的两道题,
一道是水果题:
还有一道是golf,砍树的题目:

准备OA的时候,简单写了这两道题目的python 代码,可惜都没遇到,在这里贴出来供大家参考。

# codeList
# shoppingCart

# check codelist fruit in order as ShoppingCart's order
# only codeList item count <= shoppingCart's item count == 1

def isMatch(codeList, shoppingList):
    # sequence match need to match from the first item
    # edge case: shoppingList is empty

    num_of_items_in_codeList, num_of_items_in_shoppingList = len(codeList), len(shoppingList)
    if num_of_items_in_codeList < 1:
        return 1
    if num_of_items_in_shoppingList < 1:
        return 0   
    idx_in_codeList, idx_in_shoppingList = 0, 0
    while idx_in_shoppingList < num_of_items_in_shoppingList:
        cur_List = codeList[idx_in_codeList]
        idx_in_cur_List = 0        

        # first match this cur_list
        while (cur_List[idx_in_cur_List] == 'anything') or (cur_List[idx_in_cur_List] == shoppingList[idx_in_shoppingList]):
            idx_in_cur_List += 1
            if idx_in_cur_List == len(cur_List):
                idx_in_codeList += 1
                print("finish matching this list {}".format(cur_List))
                break
            idx_in_shoppingList += 1
            if idx_in_shoppingList == num_of_items_in_shoppingList:
                break
        idx_in_shoppingList += 1

        if idx_in_codeList == num_of_items_in_codeList:
            return 1
    return 0


if __name__ == "__main__":
    codeList = [["apple", "apple"], ["orange", "banana", "orange"]]
    shoppingList = ["orange", "apple", "apple", "orange", "banana", "orange"]
    print(codeList, shoppingList, isMatch(codeList, shoppingList))

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

            if cur_node.hashstr in visited1:
                step = visited1[cur_node.hashstr] + visited2[cur_node.hashstr]
                return step

            left  = Cell(cur_node.x,   cur_node.y-1)
            right = Cell(cur_node.x,   cur_node.y+1)
            top   = Cell(cur_node.x-1, cur_node.y)
            down  = Cell(cur_node.x+1, cur_node.y)

            if isValidMove(input, left,  visited2):
                end_path.append(left)
            if isValidMove(input, right, visited2):
                end_path.append(right)
            if isValidMove(input, top,   visited2):
                end_path.append(top)
            if isValidMove(input, down,  visited2):
                end_path.append(down)

        # end this step
        step += 1
        #print("ending this step")
    return -1


if __name__ == "__main__":
    test1 = [[1,1,0,1], [1,1,5,1]]     
    print(test1, 1, minMoveGolf(test1))

    test2 = [[1,3,0,2], [1,1,3,1]]
    print(test2, 5, minMoveGolf(test2))

    test3 = [[1,0],[3,2]]
    print(test3, -1, minMoveGolf(test3))

    test4 = [[1,1,0,12,1,1],[1,1,1,1,1,1],[0,1,0,0,0,1],[0,1,1,1,14,1],[0,0,0,0,1,1],[15,1,1,1,1,1,1]]
    print(test4, 14, minMoveGolf(test4))



评分

参与人数 1大米 +1 收起 理由
bre001 + 1 感谢分享!

查看全部评分


上一篇:twitter SRE 店面
下一篇:亚麻OA

本帖被以下淘专辑推荐:

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

本版积分规则

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