📣 黑五价提前开抢|VIP一年通行证5折,蓝莓、Offer多多同步特惠
回复: 11
跳转到指定楼层
上一主题 下一主题
收起左侧

roblox oa 有测试样例 求加米!!

全局:

2022(7-9月) 码农类General 本科 实习@roblox - 网上海投 - 其他  | 😐 Neutral 😐 Average | Other | 其他

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

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

x
2. 字符串处理
You are given a non-negative integer number represented as a string of digits, and a positive integer k. Your task is to perform the following algorithm:
If the length of the number is less than or equal to k, end the algorithm. Otherwise proceed to the next steps;
Split the number into groups of k digits in each. The last group may contain less than k digits;
Add up the digits in each group, and concatenate these results in the same order;
Replace the number with the result of step 3 and go back to step 1.
Return the resulting string number after the algorithm ends.
It is guaranteed that the algorithm will end at step 1 at some point.
Example
For number = "1111122222" and k = 3, the output should be solution(number, k) = "132".
Expand to see the example video.
The number has length 10 > k, so we proceed to the next steps;
We split number into groups of size k = 3: [111, 112, 222, 2]. Note that the last group is not full and has only one digit;
We add up the digits in each group, and concatenate the results. Thus, the new value of number becomes "3462";
We start again with step 1: number has length 4 > k, so we proceed to the next steps;
We split number into groups of size k = 3: [346, 2];
We add up the digits in each group, and concatenate the results, the new number is "132";
The length of the new number is 3 = k, so the algorithm ends with "132" as a result.
For number = "1111122222" and k = 5, the output should be solution(number, k) = "510".
Expand to see the example video.
We successfully proceed step 1 and split the number into groups of k = 5 digits on step 2: [11111, 22222];
We add up the digits in each group, and concatenate the results, and the number becomes "510";
The new number has length 3 < k, so we finish the algorithm and return the string "510".
Input/Output
[execution time limit] 0.5 seconds (cpp)
[input] string number
A string of digits representing the initial number. It is guaranteed that the given string contains only digits and doesn't contain leading zeros (unless the number is 0).
Guaranteed constraints:
1 ≤ number.length ≤ 1000.
[input] integer k
The size of the groups number should be split into.
Guaranteed constraints:
3 ≤ k ≤ 1000.
[output] string
The string on which the algorithm ends.

Test 5
Input:
number: "111000222"
ɨ
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限 或 查看其他获取积分的方式
Unlock interview details and practice with AI
Popular Interview Questions from Top Companies
ut and console logs.
Test 6
Input:
chunks:
[[1000000000000,1000000000000],
[1000000000000,1000000000000],
[10000000000,100000000000]]
Expected Output:
[1, 1, 90000000002]
Click the "Run Tests" button to see output and console logs.
Test 7
Input:
chunks:
[[1,10],
[10,100],
[100,1000],
[1000,10000]]
Expected Output:
[10, 100, 1000, 10000]
Click the "Run Tests" button to see output and console logs.
Test 8
Input:
chunks:
[[1,2],
[1,16],
[1,9],
[1,44],
[1,38]]
Expected Output:
[2, 16, 16, 44, 44]
Click the "Run Tests" button to see output and console logs.
Test 9
Input:
chunks:
[[20,24],
[20,31],
[20,49],
[20,91],
[20,89]]
Expected Output:
[5, 12, 30, 72, 72]
Click the "Run Tests" button to see output and console logs.
Test 10
Input:
chunks:
[[242319992485,888494425039],
[890253050257,893986666716],
[888022315788,983197327824],
[375477269778,544174442651],
[372646369775,471869607388],
[104710990462,767613232623],
[885899371431,984870237450],
[590383734375,800503393032],
[605928833001,947931236759],
[948695791408,988903707680],
[773919986477,782808658175],
[251948207514,573096090660],
[90130840141,347207472243],
[111095701427,417671009162],
[697732084372,898883057010]]
Expected Output:
[646174432555, 649908049015, 740877335340, 740877335340, 740877335340, 878486337363, 880159246989, 880159246989, 880159246989, 884192717219, 884192717219, 884192717219, 898772867540, 898772867540, 898772867540]
Click the "Run Tests" button to see output and console logs.

评分

参与人数 6大米 +15 收起 理由
yuehan + 1 很有用的信息!
WalkOnWater + 1 很有用的信息!
Iamnickchang + 1 很有用的信息!
匿名用户-UPMT1 + 10
alannesta + 1 很有用的信息!

查看全部评分


上一篇:求加米 新鲜SnowFlake Infrastructure Automation Intern OA 和解法
下一篇:求问Tiktok NG VO面试内容
推荐
 楼主| Samuel1104 2021-11-17 10:16:52 | 只看该作者
全局:
Sunny_cat 发表于 2021-11-16 17:20
最后一题除了暴力解,有更优的办法吗

我想到一个,可以用set存区间数组的每个端点,查找的时候用数组暂存一下set,二分查找一下,更新的时候对set insert和erase,复杂度是logn的,所以总的复杂度可以降到O(nlogn)
回复

使用道具 举报

推荐
 楼主| Samuel1104 2021-11-17 10:08:14 | 只看该作者
全局:
Sunny_cat 发表于 2021-11-16 17:20
最后一题除了暴力解,有更优的办法吗

这题我的想法基本上就是遍历维护区间数组,是O(n^2)的

遍历数组的时候可以二分找,但是感觉更新数组删改还是要O(n),不知道怎么优化数据结构
回复

使用道具 举报

推荐
 楼主| Samuel1104 2021-11-17 10:19:33 | 只看该作者
全局:
Samuel1104 发表于 2021-11-16 18:16
我想到一个,可以用set存区间数组的每个端点,查找的时候用数组暂存一下set,二分查找一下,更新的时候对 ...

更正一下,直接用set lowerbound和upperbound函数
回复

使用道具 举报

🔗
alannesta 2021-11-16 06:10:32 | 只看该作者
全局:
谢谢分享, 这排版略显感人. 如果能直接上图就更好了
回复

使用道具 举报

🔗
 楼主| Samuel1104 2021-11-16 06:13:27 来自APP | 只看该作者
全局:
alannesta 发表于 2021-11-15 14:10:32
谢谢分享, 这排版略显感人. 如果能直接上图就更好了
hh没考虑到 下次注意。 求米啊朋友
回复

使用道具 举报

🔗
alannesta 2021-11-16 06:15:40 | 只看该作者
全局:
Samuel1104 发表于 2021-11-15 17:13
hh没考虑到 下次注意。 求米啊朋友

已加, 收米@@
回复

使用道具 举报

🔗
 楼主| Samuel1104 2021-11-16 06:16:30 来自APP | 只看该作者
全局:
hh谢谢朋友👍
回复

使用道具 举报

🔗
Sunny_cat 2021-11-17 09:20:04 | 只看该作者
全局:
最后一题除了暴力解,有更优的办法吗
回复

使用道具 举报

🔗
扎u扎u 2021-11-17 11:19:41 | 只看该作者
全局:
谢谢分享 但是我看不懂第四题。。
回复

使用道具 举报

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

本版积分规则

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