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

Uber OA 感恩吐血大放送 求米

 
🔗
匿名用户-WDG6A  2020-12-14 07:50:14 |倒序浏览

2020(10-12月) 码农类General 本科 全职@uber - 猎头 - 在线笔试  | 😐 Neutral 😐 Average | Other | 在职跳槽
看了 20 个 OA 帖, 4 道题有一道是原题, 还有一道是变种. Code signal 题目真的太多了, 所以不可能都看全. 最后 得了 844 分, 满分 855? 还是 1200? 不很清楚是怎么算的分数. 不过我每一道题都是 300/300 满分过的. 希望这个帖子能帮助到大家, 也希望大家给我加一点米

Quesiton 1
You are given an integer n. Your task is to calculate how many times the digits 0, 2 and 4 appear in all the non-negative integers up to n (0, 1, ...., n).
Example
• For n = 10, the output should be countOccurrences(n) = 4.
  ○ The digit 0 appears in numbers 0 and 10 once, for a total of 2 occurrences,
  ○ The digit 2 appears in the number 2 once, for a total of 1 occurrence,
  ○ The digit 4 appears in the number 4 once, for a total of 1 occurrence.So the answer is 2 + 1 + 1 = 4.
• For n = 22, the output should be countOccurrences(n) = 11.
  ○ The digit 0 appears in numbers 0, 10, and 20 once, for a total of 3 occurrences,
  ○ The digit 2 appears in numbers 2, 12, 20, and 21 once, and in the number 22 twice, for a total of 6 occurrences,
  ○ The digit 4 appears in numbers 4 and 14 once, for a total of 2 occurrences.So the answer is 3 + 6 + 2 = 11.
Input/Output
• [execution time limit] 4 seconds (py3)
• [input] integer nAn integer.Guaranteed constraints:0 ≤ n ≤ 1000.
• [output] integerThe overall count of occurrences of digits 0, 2 and 4 in the integers from 0 to n inclusive.
[Python 3] Syntax Tips
# Prints help message to the console# Returns a stringdef helloWorld(name):    print("This prints to the console when you Run Tests")    return "Hello, " + name


Quesiton 2
You are given a string str containing only the letters W, D, and L. Your task is to construct a new string from the characters of str, according to the following algorithm:
1. Begin with an empty string output = "".
2. If str contains a W, then remove it and concatenate a W to the end of output.
3. If str contains a D, then remove it and concatenate a D to the end of output.
4. If str contains an L, then remove it and concatenate an L to the end of output.
5. If str is empty, end the algorithm; otherwise go back to step 2.
Return the value of output after the algorithm is complete.
Note that it doesn't matter from where you remove the letter from the string, only the count of the letters left in the string matters.
Example
• For str = "LDWDL", the output should be equallyRearranging(str) = "WDLDL".
  ○ str contains all W, D, and L, so we add them to the output and remove from the initial string one by one and get "WDL"
  ○ The remaining string contains only letters D and L, so we a
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
;b", "e", "a", "a"] and its corresponding cyclic string is "abeaa",
  ○ The diagonal with index 6 is ["c", "a", "c", "g"] and its corresponding cyclic string is "cacgc",
  ○ The diagonal with index 7 is ["a", "c", "b"] and its corresponding cyclic string is "acbac",
  ○ The diagonal with index 8 is ["b", "b"] and its corresponding cyclic string is "bbbbb",
  ○ The diagonal with index 9 is ["b"] and its corresponding cyclic string is "bbbbb".The lexicographical ordering of the matrix diagonals looks like ["aaaaa", "abeaa", "abeab", "acbac", "bbbbb", "bbbbb", "bbbbb", "cacgc", "cadbc"], so the answer is [1, 5, 3, 7, 2, 8, 9, 6, 4].Note that the cyclic string "bbbbb" occurs 3 times, and the indices corresponding to this cyclic string appear in ascending order in the output: [2, 8, 9].
Input/Output
• [execution time limit] 4 seconds (py3)
• [input] array.array.char aA square matrix of characters. It is guaranteed that the characters in the matrix are all lowercase English letters.Guaranteed constraints:2 ≤ a.length ≤ 100,a[i].length = a.length.
• [output] array.integerAn array of size 2n - 1, containing the indices of the diagonals after sorting.
[Python 3] Syntax Tips
# Prints help message to the console# Returns a stringdef helloWorld(name):    print("This prints to the console when you Run Tests")    return "Hello, " + name

本帖子中包含更多资源

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

x

评分

参与人数 17大米 +50 收起 理由
baott + 1 给你点个赞!
itssybruce + 1 很有用的信息!
一片云的猫 + 1 给你点个赞!
zcinus + 2 给你点个赞!
uvewiuysyj + 1 给你点个赞!

查看全部评分


上一篇:脸pe面
下一篇:FB PE 2020年12月一轮店面+Linux基础复习笔记
推荐
longjia 2021-1-30 09:22:06 | 只看该作者
全局:
第三题 看了10分钟才明白问什么
回复

使用道具 举报

推荐
剑心 2021-1-29 13:02:39 | 只看该作者
全局:
第三题还以为需要DP(还不会),结果晚饭后定神看看貌似一个循环就可以解出来,就是把algo改动之后再计算...
  1. function maxRevenueFromStocks(prices: number[], algo: number[], k: number) : number {
  2.   let ret
  3.   for (let i = 0; i <= algo.length - k; i++)
  4.   {
  5.     const tmpAlgo = algo.slice().fill(1, i, i + k)
  6.     const tmpRevenue = prices.map((val, index) => tmpAlgo[index] === 0 ? -val : val).reduce((prev, curr) => prev + curr)
  7.     if (!ret) {
  8.       ret = tmpRevenue
  9.     }
  10.     if (tmpRevenue > ret) {
  11.       ret = tmpRevenue
  12.     }
  13.   }
  14.   return ret
  15. }
  16. console.log(maxRevenueFromStocks([2, 4, 1, 5, 2, 6, 7], [0, 1, 0, 0, 1, 0, 0], 4))
复制代码
回复

使用道具 举报

地里匿名用户
推荐
匿名用户-VX5KM  2023-2-2 11:53:40
第三題sliding window 可以解吧?
麻煩不吝指正

  1. func max(a, b int) int {
  2.         if a > b {
  3.                 return a
  4.         }
  5.         return b
  6. }
  7. func buySell(prices []int, algo []int, k int) int {
  8.         //sliding window
  9.         diff := 0
  10.         total := 0
  11.         for i := range prices {
  12.                 if algo[i] == 0 {
  13.                         total -= prices[i]
  14.                 } else {
  15.                         total += prices[i]
  16.                 }
  17.         }
  18.         //init
  19.         for i := 0; i < k; i++ {
  20.                 if algo[i] == 0 {
  21.                         diff += 2 * prices[i]
  22.                 }
  23.         }
  24.         max_diff := diff
  25.         for i := k; i < len(prices); i++ {
  26.                 if algo[i] == 0 {
  27.                         diff += 2 * prices[i]
  28.                 }
  29.                 if algo[i-k] == 0 {
  30.                         diff -= 2 * prices[i-k]
  31.                 }
  32.                 max_diff = max(max_diff, diff)
  33.         }
  34.         return total + max_diff
  35. }

  36. func main() {
  37.         prices, algo, k := []int{2, 4, 1, 5, 2, 6, 7}, []int{0, 1, 0, 0, 1, 0, 0}, 4
  38.         res := buySell(prices, algo, k) // 21
  39. }
复制代码
回复

使用道具 举报

🔗
workworkhard 2020-12-14 16:41:27 | 只看该作者
全局:
想问楼主第一题怎么做的
回复

使用道具 举报

🔗
xi3047 2020-12-19 14:15:03 | 只看该作者
全局:
这第四题我做了下 要短时间做到bugfree很不容易啊,太坑了
回复

使用道具 举报

🔗
剑心 2021-1-29 09:36:55 | 只看该作者
全局:
workworkhard 发表于 2020-12-14 00:41
想问楼主第一题怎么做的

这一个题按requirement和constraint,如下的解法应该就够了:
//讨巧用正则匹配处理了
  1. function countOccurrences(n: number): number {
  2.   if(n < 2) {
  3.     return 1
  4.   }
  5.   let ret = 1
  6.   const numStrs = []
  7. for (let i = 2; i <= n;i++) {
  8.   numStrs.push('' + i)
  9. }

  10. const matched = numStrs.join('').match(/[024]/g)
  11. return ret + matched.length
  12. }
复制代码
回复

使用道具 举报

🔗
剑心 2021-1-29 09:49:12 | 只看该作者
全局:
Or like this:
  1. function countOccurrences(n: number): number {
  2.   if (n < 2) {
  3.     return 1;
  4.   }
  5.   let ret = 1;
  6.   for (let i = 2; i <= n; i++) {
  7.    const matched = ("" + i).match(/[024]/g)
  8.    if (matched) {
  9.      ret += matched.length
  10.    }
  11.   }
  12.   return ret
  13. }
复制代码
回复

使用道具 举报

🔗
剑心 2021-1-29 10:25:38 | 只看该作者
全局:
我想了解第二题还有更好的解法吗?
  1. function equallyRearranging(str: string): string{
  2.   let ret = ''
  3.   while(str.length) {
  4.     if(str.includes('W')) {
  5.       str = str.replace('W', '')
  6.       ret += 'W'
  7.     }
  8.     if(str.includes('D')) {
  9.       str = str.replace('D', '')
  10.       ret += 'D'
  11.     }
  12.     if(str.includes('L')) {
  13.       str = str.replace('L', '')
  14.       ret += 'L'
  15.     }
  16.   }
  17.   return ret
  18. }
复制代码
回复

使用道具 举报

全局:
第三题,是不是双指针?
回复

使用道具 举报

全局:
第二题,可以数3个字母出现次数,然后拼出来吗?
回复

使用道具 举报

全局:
一个oa这么多题目?感觉做的快吐了吧
回复

使用道具 举报

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

本版积分规则

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