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

[TeamMatch] Amazon Online Assessment OA 刚做完,把题目分享给大家,换点大米

   
🔗
ciacia7621 2021-10-14 11:52:22 | 只看该作者
全局:
iyarik 发表于 2021-9-23 12:48
谢谢分享! 第二个问题是 LC828

还是不太一样,描述类似,但题意差了不少
回复

使用道具 举报

🔗
guiguia 2021-10-17 13:15:11 | 只看该作者
全局:
谢谢楼主分享。
第二题O(n)应该可以做:
       public int passwordStrength(String s) {
        int n = s.length();. 1point3acres.com
        int[] last = new int[26];.
        Arrays.fill(last, -1);
        int ans = 0;
        int cur = 0;.1point3acres
        for (int i = 0; i < s.length(); i++) {
            int index = s.charAt(i) -'a';
            cur += i + 1 - (last[index] + 1);
            ans += cur;
            last[index] = i;
        }
        return ans;
    }
    dp[i]: number of distinct letters for all substring end at i
    last[i]: last index for each letter
    There are total (i + 1) substring at [0, i]. letter i add at most i + 1 new distinct letter in dp[i]
    also need to substract previous substring count which already having letter i, which is lastIndex + 1
     dp[i] = dp[i - 1] + i + 1 - (lastIndex + 1) => cur = cur + i + 1 - (lastIndex + 1)
    Time complexity: O(n)
    Space complexity: O(1)

评分

参与人数 1大米 +1 收起 理由
Thornthwaite + 1 nb

查看全部评分

回复

使用道具 举报

🔗
kobegao 2021-10-18 07:24:47 | 只看该作者
全局:
第一题 python 代码,试了几个test cases 好像都是对的,如果有不对的地方,请大佬们指点
  1. #####helper funciton don't delete or change
复制代码
回复

使用道具 举报

🔗
kobegao 2021-10-18 07:28:42 | 只看该作者
全局:
kobegao 发表于 2021-10-17 19:24
第一题 python 代码,试了几个test cases 好像都是对的,如果有不对的地方,请大佬们指点

上个回复复制错了,不知道怎么改不了,再发下
  1. class Node:
  2.     def __init__(self,data,next = None):
  3.         self.data = data
  4.         self.next = next. 1point3acres

  5. def insert(root,val):
  6.     if not root:
  7.         root = Node(val)
  8.     else:
  9.         cur = root
  10.         while cur.next: ..
  11.             cur = cur.next
  12.         cur.next=Node(val). ----
  13.     return root. .и
  14. def listToNode(numbers):
  15.     root = None
  16.     for num in numbers:.
  17.         root = insert(root,num)
    .1point3acres
  18.     return root

  19. #####helper funciton don't delete or change
  20. def reverseLinkedList(node):. From 1point 3acres bbs
  21.     prev = None
  22.     while node:
  23.         next = node.next
  24.         node.next = prev
  25.         prev = node
  26.         node = next. ----
  27.     return prev. ----

  28. def maxinumPages(head):. ----
  29.     slow = head
  30.     fast = head.next
  31.     while fast and fast.next:
  32.         fast = fast.next.next
  33.         slow = slow.next

  34.     new_head = slow.next
  35.     slow.next = None
  36.     rev_head = reverseLinkedList(new_head)
  37.     max_pages = 0 ..
  38.     while head or rev_head:
  39.         if head:
  40.             p1 = head.data
  41.             head = head.next
  42.         else:
  43.             p1 = 0

  44.         if rev_head:
  45.             p2 = rev_head.data.
  46.             rev_head = rev_head.next
  47.         else:
  48.             p2 = 0
  49.         max_pages = max(max_pages,p1+p2)
  50. . ----
  51.     return max_pages
  52. # numbers = [1,4,3,2]
  53. # numbers = [3,1,1,3]
  54. numbers = [3,1,9,3,3]
  55. head = listToNode(numbers)
  56. print(maxinumPages(head))
复制代码
回复

使用道具 举报

🔗
蟹大叔 2021-11-2 08:57:12 | 只看该作者
全局:
guiguia 发表于 2021-10-16 22:15
谢谢楼主分享。
第二题O(n)应该可以做:
       public int passwordStrength(String s) {

Good one!
回复

使用道具 举报

🔗
SteinGate 2021-11-13 12:31:54 | 只看该作者
全局:
iyarik 发表于 2021-9-23 12:48
谢谢分享! 第二个问题是 LC828

这题和828还不一样。感觉828比这题难不少。我们来看一个例子就知道了。
828的要求:
For example if s = "LEETCODE" then "L", "T", "C", "O", "D" are the unique characters since they appear only once in s, therefore countUniqueChars(s) = 5.
所以如果character在这个substring里重复,它是不能被记入最后结果的
. Χ
再来看亚麻的OA:
test => 3
这道题里,t尽管重复了,但是它被记入了一次。所以这两道题对于 countUniqueChars()的定义是不同的。
回复

使用道具 举报

全局:
naturalbeau 发表于 2021-9-24 15:24
第一题先用快慢指针分两半,然后把后半段reverse,然后再两个list相加。

大佬可以发一下sudo code嘛
回复

使用道具 举报

🔗
exyman3fendi 2021-12-25 17:03:13 | 只看该作者
全局:
SteinGate 发表于 2021-11-12 20:31
这题和828还不一样。感觉828比这题难不少。我们来看一个例子就知道了。
828的要求:
For example if s  ...

如果只记录一次,应该更简单
dp[ i ] 代表从0开始 以 i 坐标结尾的substring的所有substring的unique 和

dp[ i ] = dp[i - 1] + (i - last occurance of s.charAt( i ))  (meaning number of new uniques the new s.charAt( i ) can contribute to dp[ i - 1]). ----
一个长26的数组记录 并更新 last occurance of s.charAt( i )
dp只用两个数组不断更新就行
回复

使用道具 举报

🔗
tycworld 2022-1-6 04:52:57 | 只看该作者
全局:
微信用户_b95b611 发表于 2021-11-26 21:35
大佬可以发一下sudo code嘛

用快慢指针找到中点的部分你可以参考 LC876

reverse list 的部分可以参考 LC206. 1point 3acres

之后就是双指针, 一个从开头, 另一个从中点, 相加取最大值就行
回复

使用道具 举报

🔗
peterxjs 2022-4-12 08:17:54 | 只看该作者
全局:
感谢楼主!祝找到满意的工作
回复

使用道具 举报

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

本版积分规则

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