HRT OA 好容易就通过了!只用了13分钟 | 2026 最新深度分享

18 Views
No Comment

老实说,这次 HRT OA 难度不算高,尤其是对我这种已经刷过很多 TikTok、Jane Street、Citadel 等量化/高频交易公司 OA 的人来说,题目非常熟悉,整体体验相当轻松。下面我把这次 OA 的真实情况、题目特点和解题思路详细分享给大家,希望能帮到正在准备 HRT OA 的同学。

HRT OA 好容易就通过了!只用了13分钟 | 2026 最新深度分享

HRT OA 整体情况

  • Platform:CodeSignal
  • Volume:4 道 Coding 题
  • Duration:90 分钟(我实际只用了 13 分钟)
  • Difficulty:Easy ~ Medium,整体偏友好

HRT 的 OA 风格和 TikTok 比较接近,题目以字符串、数组、数学模拟、简单贪心/DP 为主,代码量不大,但需要思路清晰、边界处理稳。

题目 1:网站评分记录

题目描述

你给喜欢的网站打分,初始分数为 1500。每次分数变化都记录在数组 diffs 中(正数加分,负数减分)。

请返回一个数组 [最高评分, 当前评分].

Example

Enter:diffs = [100, -200, 350, 100, -600]

Process:

  • 初始:1500
  • 1500 + 100 = 1600
  • 1600 – 200 = 1400
  • 1400 + 350 = 1750
  • 1750 + 100 = 1850 (最高)
  • 1850 – 600 = 1250 (当前)输出:[1850, 1250]

Approach to Solving the Problem

  1. initialization current = 1500,max_rating = 1500
  2. (math.) ergodic diffs,每次更新 current,并更新 max_rating
  3. 最后返回 [max_rating, current]

Python 代码

def solution(diffs):
    current = 1500
    max_rating = current
    for d in diffs:
        current += d
        if current > max_rating:
            max_rating = current
    return [max_rating, current]

题目 2:穿梭机行程时间计算

题目描述

你需要在星球 Alpha 和 Beta 之间往返完成 missions 次任务(每次任务:Alpha→Beta→Alpha)。

  • alpha2beta:从 Alpha 出发的穿梭机出发时间(按时间顺序排列),单程耗时 100 个时间单位。
  • beta2alpha:从 Beta 出发的穿梭机出发时间(按时间顺序排列),单程耗时 100 个时间单位。每次都选择最早可乘坐的班次。请计算完成所有任务的总时间。

Example

Enter:alpha2beta = [0, 200, 500], beta2alpha = [99, 210, 450], missions = 1

Process:

  1. 坐 Alpha 0 点的穿梭机,100 到达 Beta
  2. 在 Beta 最早能坐 210 出发的穿梭机,310 回到 Alpha输出:310

Approach to Solving the Problem

  1. Maintain current time time = 0
  2. 循环 missions 次:
    • 找到第一个 >= time (used form a nominal expression) alpha2beta 班次,到达 Beta 的时间是 班次时间 + 100
    • 用到达 Beta 的时间,找到第一个 >= 到达Beta时间 (used form a nominal expression) beta2alpha 班次,回到 Alpha 的时间是 班次时间 + 100
    • 更新 time 为回到 Alpha 的时间
  3. 返回最终的 time

Python 代码

def solution(alpha2beta, beta2alpha, missions):
    time = 0
    for _ in range(missions):
        # 去程:找第一个 >= 当前时间的班次
        for dep in alpha2beta:
            if dep >= time:
                time = dep + 100  # 到达Beta
                break
        # 返程:找第一个 >= 到达Beta时间的班次
        for dep in beta2alpha:
            if dep >= time:
                time = dep + 100  # 回到Alpha
                break
    return time

题目 3:报纸排版

题目描述

Given Paragraphs(二维数组,每个子数组是一段的文本块)和 Width(每行最大字符数,不含边框),需要生成居中对齐、带星号边框的报纸页面:

  1. 每段从新行开始,文本块用空格连接,不能拆分单个文本块。
  2. 若一行文本(含空格)长度小于 Width,需要居中:
    • 剩余空间为偶数:前后空格数相同
    • 剩余空间为奇数:前面比后面少一个空格(或题目描述为前面和后面相等,多的一个放后面)
  3. 外围用 * 做边框,返回每一行的字符串数组。

Approach to Solving the Problem

  1. 文本分行:none:
    • 遍历每个段落,按规则把文本块拼成一行,长度不超过 Width
    • 文本块之间用空格连接
  2. 居中处理:none:
    • 计算剩余空格 pad = width - len(line)
    • 前空格数 left = pad // 2,后空格数 right = pad - left
    • 生成居中后的行
  3. 加边框:none:
    • 首尾行:* 重复 width + 2
    • 中间行:* + 居中后的文本 + *

Python 代码

def solution(paragraphs, width):
    lines = []
    # 步骤1:分行
    for para in paragraphs:
        current_line = []
        current_len = 0
        for chunk in para:
            if not current_line:
                # 新行直接加
                current_line.append(chunk)
                current_len = len(chunk)
            else:
                needed = current_len + 1 + len(chunk)
                if needed <= width:
                    current_line.append(chunk)
                    current_len = needed
                else:
                    # 结束当前行
                    lines.append(' '.join(current_line))
                    current_line = [chunk]
                    current_len = len(chunk)
        if current_line:
            lines.append(' '.join(current_line))
    # 步骤2:居中
    centered = []
    for line in lines:
        pad = width - len(line)
        left = pad // 2
        right = pad - left
        centered_line = ' ' * left + line + ' ' * right
        centered.append(centered_line)
    # 步骤3:加边框
    border = '*' * (width + 2)
    result = [border]
    for line in centered:
        result.append('*' + line + '*')
    result.append(border)
    return result

题目 4:锯齿序列子数组计数

题目描述

定义一个锯齿序列:相邻元素的奇偶性交替变化(如:奇 – 偶 – 奇 – 偶… 或 偶 – 奇 – 偶 – 奇…)。

given array Arr,统计所有连续子数组中,满足锯齿序列条件的子数组数量(长度≥1)。

Example

  1. arr = [1,3,5,7,9]:所有元素都是奇数,只有长度为 1 的子数组满足条件 → 答案 5
  2. arr = [1,2,1,2,1]:所有连续子数组都满足条件 → 总数 5*(5+1)/2 = 15
  3. arr = [1,2,3,7,6,5]:不满足条件的位置是 3 And 7(都是奇数),所以分段统计:
    • [1,2,3]:长度 3,子数组数 3*4/2=6
    • [7,6,5]:长度 3,子数组数 3*4/2=6合计 12

Approach to Solving the Problem

  1. Key observations:连续子数组是否为锯齿序列,取决于相邻元素的奇偶性是否交替。
    • 先把数组转换成奇偶性数组(0 = 偶,1 = 奇)
    • 再转换成 “奇偶性是否变化” 的数组:diff[i] = 1 if arr[i]%2 != arr[i+1]%2 else 0
  2. Turn up diff 数组中连续为 1 的段,设某段长度为 L,则该段对应的锯齿子数组数量为 (L+1)*(L+2)//2
    • For example L=2(3 个元素,2 次奇偶交替),子数组数 3*4/2=6
  3. (math.) ergodic diff 数组,统计所有连续段的贡献,就是最终答案。

Python 代码

def solution(arr):
    if not arr:
        return 0
    # 转换为奇偶数组
    parity = [x % 2 for x in arr]
    n = len(parity)
    total = 0
    current_length = 1  # 当前连续锯齿序列的长度
    for i in range(1, n):
        if parity[i] != parity[i-1]:
            current_length += 1
        else:
            # 结算当前段的贡献
            total += current_length * (current_length + 1) // 2
            current_length = 1
    # 加上最后一段的贡献
    total += current_length * (current_length + 1) // 2
    return total

备战心得与建议

题型熟悉度最重要 HRT、TikTok、Jane Street 这类公司的 OA 题库重合度较高。建议大家平时多刷 CodeSignal 的 Arcade 和 Company Tagged 题目,尤其是字符串、数组、贪心、DP 四大类。

速度与准确性并重 虽然题目不难,但一定要注意边界条件(空数组、空字符串、单元素、最大值等)。我每次练习都会强制自己先写注释,理清楚思路再动手。

养成每天刷题的习惯 我最近几乎每天都做 1-2 份完整 OA(包括 HRT、TikTok、Citadel 等),熟悉了题型和节奏后,真实考试时心态会非常稳。

如果 OA 和 VO 没把握 对于 OA 稳定性要求高、VO 压力大的同学,可以考虑一些实战辅助支持。Program assistance 在这方面经验比较丰富,他们的学长做过很多家大厂的 OA 和 VO 辅导,能提供针对性的思路指导。

author avatar
Jory Wang Senior Software Engineer at Amazon
Senior Engineer at Amazon, specializing in the development of core systems within infrastructure, with extensive practical experience in system scalability, reliability, and cost optimization. Currently focused on FAANG SDE interview preparation, assisting over 30 candidates in securing L5/L6 offers within a year.
END
 0