回复: 2
收起左侧

OKX HK Hackerrank

匿名用户-DKOXQ  2024-11-14 15:08:22
本楼:   👍  0
0%
0%
0   👎

2023(1-3月) 码农类General 本科 全职@OKX - Other - 在线笔试  | 😐 Neutral 🤓 EasiestOther | 其他

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

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

x

没想到那么简单,求大米


T1: Given an array `arr` of `n` non-negative integers and an array `power` of `k` integers where `k` is an even number, perform the following operation in steps.

- Select two integers `i` and `j` such that `0 ≤ i < j < |power|`. In each operation, `i` and `j` are selected independently.
  - If `power[i] = power[j]`, add the summation of the subarray `arr[power[i]...power[j]]` to the power.
  - If `power[i] > power[j]`, add the summation of the subarray `arr[power[j]...power[i]]` to the power.
  - Delete `i`-th and `j`-th elements from `power`, and its length is reduced by 2.

Starting at 0 initial power, maximize the final power after exactly `k/2` operations. Return that maximum power modulo `(10^9 + 7)`.

**Note:** Subarray `arr[l...r]` denotes the subarray formed by the elements `arr[l], arr[l+1], ..., arr[r-1], arr[r]`.

#### Example:
```
arr = [3, 5, 6, 0, 7], power = [3, 1, 0, 2]
k = 4, the size of power, so perform k/2 = 2 operations.
```

One of the optimal approaches is shown:

```
- Select i=0, j=2. Here, power[0] = 3 and power[2] = 0. Add the sum of subarray `arr[0...3]` (3 + 5 + 6 + 0 = 14) to the power. 0 + 14 = 14. Remove the two elements from power, and power is [1, 2].
- Select i=0, j=1. Here, power[0] = 1 and power[1] = 2. Add the sum of subarray `arr[1...2]` 5 + 6 = 11, so power is 14 + 11 = 25.
```

题解
您好!
本帖隐藏的内容需要积分高于 123 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 123 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式


T2:
Given a permutation `p` of length `n` denoted by `p = [p1, p2,..., pn]`, a number `k` is balanced if there are two indices `l`, `r` (1 ≤ l ≤ r ≤ n), such that the numbers `[p[l], p[l+1], ..., p[r]]` form a permutation of the numbers `1, 2, ..., k`.

For each `k` (1 ≤ k ≤ n), determine if it is a balanced number or not. Return a binary string `ans` of length `n`, where the `i-th` character of the string (considering 1-based indexing) is '1' if `i` is a balanced number and '0' otherwise.

**Note:** A permutation of length `n` contains each integer from 1 to `n` exactly once in any order.

#### Example:
Consider `n = 4`, `p = [4, 1, 3, 2]`.

- For `k = 1`: Choose `l = 2` and `r = 2`, the chosen `p[2:2] = {1}`, a permutation of length 1.
- For `k = 2`: No pair of indices results in a permutation of length 2. It is not a balanced number.
- For `k = 3`: `l = 2, r = 4, p[2:4] = [1, 3, 2], a permutation of length 3.
- For `k = 4`, `l = 1, r = 4, p[1:4] = [4, 1, 3, 2], a permutation of length 4.

The balanced numbers are 1, 3, and 4, while 2 is not balanced. The answer is `"1011"`.

题解
您好!
本帖隐藏的内容需要积分高于 123 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 123 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式


选择题还是比较简单的

您好!
本帖隐藏的内容需要积分高于 123 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 123 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式

评分

参与人数 1大米 +10 收起 理由
清道神君 + 10 欢迎分享你知道的情况,会给更多大米奖励!

查看全部评分


上一篇:Meta E4 VO过经
下一篇:开放AI点面挂经-11月coding新题
6godfather9 2024-12-6 20:25:47 | 显示全部楼层
本楼:   👍  0
0%
0%
0   👎
全局:   0
0%
0%
0
同收到oa 请问你开始面试了吗
回复

使用道具 举报

地里匿名用户
匿名用户-DKOXQ  7 天前
本楼:   👍  0
0%
0%
0   👎
6godfather9 发表于 2024-12-6 06:25
同收到oa 请问你开始面试了吗

收到面试邀请了,还没开始面
扫码关注一亩三分地求职移民公众号
更多干货内容等你发现
回复

使用道具 举报

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

本版积分规则

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