JPMorgan OA 面经分享|动态规划 + 前缀和题型总结

356閱讀
沒有評論

JPMorgan 的 OA 一直是很多准备金融科技岗(FinTech / Quant / Data / SDE)的同学关注的重点环节。它不像纯算法公司那样只看代码能力,也不像传统投行那样偏向行为题,而是两者结合:题目简短却逻辑性极强,往往要在限定时间内迅速读懂场景、抽象出数学模型,再落地成可执行的代码。

我这次做的是 JPMorgan 的最新一版 OA,整体题量 2 道,时间相对充裕,但对思维转换速度要求挺高。第一题是一个典型的 前缀和+差值分析 问题,看似简单但需要精确计算每个切割点的最优方案;第二题则是偏 动态规划(DP) 思路的路径求和题,重点在状态转移和边界处理。两题都属于那种“一旦想通就很好写,但想通之前极容易卡”的类型。

这类题其实非常能体现 JPMorgan 的出题风格——考察逻辑推理能力、计算思维,还有对代码可读性的把控。对新毕业生或者实习生来说,它不单纯是算法题,而更像是一个小型逻辑建模测试。

JPMorgan OA 面经概览

整个 OA 一共两道题,时间不算特别紧,但题意略绕,需要仔细读。
我这次顺利 AC,主要靠前期对类似题型(前缀和 + DP)的熟悉度。

Problem 1: Balance Two Parts of an Array

Description:
Given a list of items with quantities, you need to split the list into two consecutive parts. You can increase or decrease the number of items in each part. The goal is to make the total quantity of both parts equal using the minimum number of operations. Each operation can increase or decrease one unit from any item.

Example:

Input: [1, 2, 5, 4]
Output: 1

Explanation:
Split between 2 and 5 gives [1,2] and [5,4].
Sum(left) = 3, Sum(right) = 9 → Difference = 6 → Need 3 operations per side → Minimum total = 3.

Approach:
Use prefix sum to compute the sum of the left and right parts efficiently.
For every split point, calculate the difference between the two sums.
The minimum number of operations equals abs(sum_left - sum_right) / 2.

Code Idea (Python):

def min_operations(nums):
    prefix = [0]
    for x in nums:
        prefix.append(prefix[-1] + x)
    total = prefix[-1]
    res = float('inf')
    for i in range(1, len(nums)):
        left = prefix[i]
        right = total - left
        res = min(res, abs(left - right) // 2)
    return res

Problem 2: Maximum Security Value After Hacker Jumps

Description:
There are n servers in a line, each with a certain security value.
A hacker starts from any server and jumps k servers forward each time (i → i+k).
The process stops when the hacker jumps out of the network.
You need to find the maximum total security value the hacker can collect from any starting position.

Example:

Input: security = [5, 7, 3, 4, 6], k = 2
Output: 13

Explanation:
Start at index 0 → nodes 0, 2, 4 → sum = 5 + 3 + 6 = 14
Start at index 1 → nodes 1, 3 → sum = 7 + 4 = 11
Maximum = 14

Approach:
Use bottom-up dynamic programming.
Let dp[i] represent the maximum total value starting from node i.
Then:

dp[i] = security[i] + dp[i+k] if i+k < n else security[i]

Finally, return max(dp) as the answer.

Code Idea (Python):

def max_security(security, k):
    n = len(security)
    dp = [0] * n
    for i in range(n - 1, -1, -1):
        dp[i] = security[i]
        if i + k < n:
            dp[i] += dp[i + k]
    return max(dp)

总结

JPMorgan 的这套 OA 整体偏算法逻辑题,重点在于:

  • 思维清晰:题意不长但容易读混;
  • 实现细节:前缀和与 DP 的索引边界要特别小心;
  • 代码可读性:不要一味追求 one-liner。

OA代写/面试助攻,JPMorgan直通Offer!

兄弟,刷题累?中介黑?别纠结了,ProgramHelp,专攻JPMorgan/FAANG OA代写,24-48小时交付,100%全TC通过,不过全退费!

  • 全链条服务:从OA代刷(DP/前缀和专攻)到HireVue脚本、VO实时提示,直到你签Offer。JPMorgan批次我已帮50+人过,近千份案例,金融题型手到擒来。
  • 零风险承诺:先模拟/交付,满意再付尾款,无中介费(比市面便宜30%),绝对原创、保密,Wechat一对一指导无限期。
  • 真实反馈:上周帮一CS学员刷JPM DP题,次日Passed,Offer到手!“学长,值了!”——她这么说。
author avatar
jor jor
正文完
 0