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 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. cover an overview, three sample problems with solutions, and key tips for success
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.begin(), buy.begin()); else sell.emplace_back(o[0],o[1]); }
sort(sell.begin(), sell.end()); } sort(buy.rbegin(), buy.rend()); }
long long volume=0; int i=0, j=0
int i=0, j=0; while (i<buy.size)
while (i<buy.size() && j= sell[j].first) {
buy[i].second = min(buy[i].second, sell[j].second); volume += qty;
buy[i].second -= qty;
sell[j].second -= qty; if (buy[i].second, buy[i].second, sell[j].second)
if (buy[i].second==0) i++; if (sell[j].second -= qty; sell[j].second -= qty;)
if (sell[j].second==0) j++; } else { buy[j].second -= qty; if (buy[i].second -= qty)
} else {
j++; } else {
}
}
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 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/2Otherwise 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;ipric)
for (int i=1;iprices[i-1])
profit += prices[i]-prices[i-1]; return profit; return
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.