Hudson River Trading Online Interview: Comprehensive Guide

1,472Views
尚無留言

The Hudson River Trading Online Assessment evaluates problem-solving and coding skills for roles like Software Engineer. Hosted on platforms such as CodeSignal, it consists of 3–4 algorithmic challenges with a total duration of 70–150 minutes. Languages commonly used include C++ and Python. Below we cover an overview, three sample problems with solutions, and key tips for success

Hudson River Trading OA

1. Order Book Matching

Problem: Given a list of buy/sell orders [price, quantity, type], match buys with sells whenever buy price ≥ sell price. Compute the total executed volume.

Example:
Input: [[100,5,'B'], [90,3,'S'], [95,2,'S'], [105,4,'B']]
Output: 5

Approach: • Separate buy orders (sort descending) and sell orders (sort ascending). • Use two pointers to match and accumulate the min(quantity) for each pair.

#include 
#include 
using namespace std;

long long matchOrders(vector<vector>& orders) {
    vector<pair> buy, sell;
    for (auto &o : orders) {
        if (o[2]=='B') buy.emplace_back(o[0],o[1]);
        else sell.emplace_back(o[0],o[1]);
    }
    sort(buy.rbegin(), buy.rend());
    sort(sell.begin(), sell.end());
    long long volume=0;
    int i=0, j=0;
    while (i<buy.size() && j= sell[j].first) {
            auto qty = min(buy[i].second, sell[j].second);
            volume += qty;
            buy[i].second -= qty;
            sell[j].second -= qty;
            if (buy[i].second==0) i++;
            if (sell[j].second==0) j++;
        } else {
            j++;
        }
    }
    return volume;
}

2. Minimum Transformations for Unique Substrings

Problem: For a string s and window length k, find the minimum character changes so every substring of length k has all unique letters.

Example:
Input: s="aabbcc", k=3 → Output: 2

Approach: • Slide a window of size k over s. • Count duplicates in each window and record the minimum needed replacements.

from collections import Counter

def minTransformations(s: str, k: int) -> int:
    def needed(w):
        cnt = Counter(w)
        return sum(v-1 for v in cnt.values() if v>1)
    return min(needed(s[i:i+k]) for i in range(len(s)-k+1))

3. Optimal Trade Execution

Problem: Given stock prices array and max k transactions, compute the maximum profit. You cannot hold more than one share at a time.

Example:
Input: prices=[3,2,6,5,0,3], k=2 → Output: 7

Approach: • If k ≥ n/2, sum all positive price jumps. • Otherwise use DP with states for transaction count and holding/not-holding.

#include 
using namespace std;

int maxProfit(int k, vector& prices) {
    int n = prices.size();
    if (k >= n/2) {
        int profit=0;
        for (int i=1;iprices[i-1])
            profit += prices[i]-prices[i-1];
        return profit;
    }
    vector<vector> dp(k+1, vector(2, -1e9));
    dp[0][0]=0; dp[0][1]=-prices[0];
    for (int i=1;i0) dp[j][1] = max(dp[j][1], dp[j-1][0] - prices[i]);
      }
    }
    return dp[k][0];
}

ProgramHelp: Beyond Interview Prep

We offer comprehensive services—from OA proxy and coding coaching to mock interviews and full‐service placement support. Contact us to accelerate your career journey. 聯絡我們 加速您的職涯發展進程。

author avatar
ProgramHelp
END
 0
Comment(尚無留言)