楼主: 匿名
跳转到指定楼层
上一主题 下一主题
收起左侧

狗家虚拟现场

🔗
cowtony 2020-7-7 12:14:32 | 只看该作者
全局:
本帖最后由 cowtony 于 2020-7-7 12:16 编辑

设S[-1] = H[0] = x,把S数组前面延申两个dummy,就好理解一些了,然后就要求每个3i + k都满足那两个不等式。可能还需要reverse S[] 然后再跑一遍算法取最小值。

本帖子中包含更多资源

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

x
回复

使用道具 举报

🔗
lch04 2020-7-8 01:48:48 | 只看该作者
全局:
"3. 一个 tree, 返回每个 key 之间的路径."

这个题我认为应该是先遍历一遍树,取出来所有的节点值放到一个数组里面,然后对数组做任意两个节点的combination,然后问题就转化为求两个确定的节点之间的路径.
这个代码可以run

  1. # Python3 program to print path between any
  2. # two nodes in a Binary Tree

  3. import sys
  4. import math


  5. # structure of a node of binary tree
  6. class Node:
  7.     def __init__(self, data):
  8.         self.data = data
  9.         self.left = None
  10.         self.right = None


  11. # Helper function that allocates a new node with the
  12. # given data and NULL left and right pointers.
  13. def getNode(data):
  14.     return Node(data)


  15. # Function to check if there is a path from root
  16. # to the given node. It also populates
  17. # 'arr' with the given path

  18. def _get_path(res, _path, _root, target):
  19.     print("In my get_path")
  20.     if not _root:
  21.         return
  22.     _path.append(_root.data)
  23.     if _root.data == target:
  24.         res.append(_path[:])
  25.         return
  26.     _get_path(res, _path, _root.left, target)
  27.     _get_path(res, _path, _root.right, target)
  28.     _path.pop()

  29. # Function to print the path between
  30. # any two nodes in a binary tree
  31. def printPathBetweenNodes(root, n1, n2):
  32.     #         # vector to store the path of
  33.     #         # first node n1 from root
  34.     #         path1 = []

  35.     #         # vector to store the path of
  36.     #         # second node n2 from root
  37.     #         path2 = []
  38.     #         getPath(root, path1, n1)
  39.     #         getPath(root, path2, n2)

  40.     my_path1 = []
  41.     my_path2 = []

  42.     _get_path(my_path1, [], root, n1)
  43.     _get_path(my_path2, [], root, n2)

  44.     path1 = my_path1[0]
  45.     path2 = my_path2[0]

  46.     # Get intersection point
  47.     i, j = 0, 0
  48.     intersection = -1
  49.     while (i != len(path1) or j != len(path2)):

  50.         # Keep moving forward until no intersection
  51.         # is found
  52.         if (i == j and path1[i] == path2[j]):
  53.             i += 1
  54.             j += 1
  55.         else:
  56.             intersection = j - 1
  57.             break

  58.     # Print the required path
  59.     for i in range(len(path1) - 1, intersection - 1, -1):
  60.         print("{} ".format(path1[i]), end="")
  61.     for j in range(intersection + 1, len(path2)):
  62.         print("{} ".format(path2[j]), end="")

  63.     # Driver program


  64. if __name__ == '__main__':
  65.     # binary tree formation
  66.     root = getNode(0)
  67.     root.left = getNode(1)
  68.     root.left.left = getNode(3)
  69.     root.left.left.left = getNode(7)
  70.     root.left.right = getNode(4)
  71.     root.left.right.left = getNode(8)
  72.     root.left.right.right = getNode(9)
  73.     root.right = getNode(2)
  74.     root.right.left = getNode(5)
  75.     root.right.right = getNode(6)
  76.     node1 = 7
  77.     node2 = 6
  78.     printPathBetweenNodes(root, node1, node2)
复制代码
回复

使用道具 举报

🔗
lch04 2020-7-8 01:53:10 | 只看该作者
全局:
"第二题 手机基站定位, inpu 是多个基站的位置坐标, 以及手机到基站的信号强度, 求具体手机的坐标. 强度信号不能直接转化成距离." 这个题看起来像是BFS?从每个基站开始遍历所有的位置,计算到该位置的强度做累加。然后再遍历一遍所有的位置如果累加的强度和等于手机的信号强度,那就返回该位置的坐标。
回复

使用道具 举报

🔗
amgfan 2020-7-8 04:08:25 | 只看该作者
全局:
lch04 发表于 2020-7-8 01:53
"第二题 手机基站定位, inpu 是多个基站的位置坐标, 以及手机到基站的信号强度, 求具体手机的坐标. 强度信 ...

数学题, 不涉及图论
回复

使用道具 举报

🔗
lch04 2020-7-8 04:30:05 | 只看该作者
全局:
amgfan 发表于 2020-7-8 04:08
数学题, 不涉及图论

那就不知道了,感觉题意说的也不是特别清楚,还请赐教啊
回复

使用道具 举报

全局:
您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 100 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
回复

使用道具 举报

全局:
lch04 发表于 2020-7-8 01:48
"3. 一个 tree, 返回每个 key 之间的路径."

这个题我认为应该是先遍历一遍树,取出来所有的节点值放到一 ...

第三题 可以求出Lowest Common Ancestor 然后再结合path
回复

使用道具 举报

🔗
AlbertZhong 2020-7-9 08:46:00 | 只看该作者
全局:
木华黎_Reid 发表于 2020-7-9 06:39
非常赞同。具体一些: 由于n是奇数,所以可以分为
1. n = 6k+1, mid = 3k
可以从2 和 n-3出发, 注意到 ...

层主的分析好。我之前只想到了大概方向,再像你这样动笔细算一下就会发现其实都是确定了的。。。
回复

使用道具 举报

🔗
旧未来 2020-7-9 14:03:10 | 只看该作者
全局:
木华黎_Reid 发表于 2020-7-9 06:39
非常赞同。具体一些: 由于n是奇数,所以可以分为
1. n = 6k+1, mid = 3k
可以从2 和 n-3出发, 注意到 ...

所以根据你的意思 最中间那个永远是个定值?
回复

使用道具 举报

🔗
EmanekaT 2020-7-12 10:45:04 | 只看该作者
全局:
楼主这是踩到雷了...
回复

使用道具 举报

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

本版积分规则

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