def max_gross_value(arr: list[int]) -> int:
Given an array arr of n integers, a triplet of 1-based indices i1, i2, i3 with 1 ≤ i1 ≤ i2 ≤ i3 ≤ n + 1 cuts the array into four consecutive segments. Its gross value is
grossValue(i1, i2, i3) = sum[1, i1) - sum[i1, i2) + sum[i2, i3) - sum[i3, n + 1)
Here sum[l, r) (1 ≤ l ≤ r ≤ n + 1) uses half-open interval notation: the range includes index l and excludes index r. When l = r, arr[l, r) is empty and sum[l, r) is 0.
Find the maximum gross value of any valid triplet.
n up to 3 * 10^3.sum[i1, i2), repeating the second term. That candidate's own summary and another report's copy of the formula both make it sum[1, i1), which is what the statement above uses. If you get this prompt, check which the formula says.Three reports mention this problem, all from Citadel online assessments in July to September 2025, where it was one of two coding problems; the other was the largest-hackathon-team problem.
The first poster (SDE campus 2025-2026) tried every triplet of cuts, O(n^3), passed about 60% of the tests with n up to 3 * 10^3, and had no idea how to optimise. A reply gave the O(n) method (fix the cut between the second and third segments, then take the best prefix before it and the best suffix after it), and the poster confirmed it was right; another reply says they had just written a version that passed everything.
A second post, summarising the OA problems in circulation, copies the formula with the first term as sum[1, i1) and includes an O(n^2) solution that fixes the middle cut and scans both sides. A reply to it asks whether anyone got full marks on this problem: everyone the replier knew who got it failed, and they suspect the test cases are wrong.
The third poster had 80 minutes for the two problems. They used prefix sums and computed the cuts from the formula, but two test cases failed; they checked with a brute force, which the platform also marked wrong, and they too suspected the test data. They also lost a lot of time to the editor inserting characters from their input method.
Given an array arr of n integers, a triplet of 1-based indices i1, i2, i3 with 1 ≤ i1 ≤ i2 ≤ i3 ≤ n + 1 cuts the array into four consecutive segments. Its gross value is
grossValue(i1, i2, i3) = sum[1, i1) - sum[i1, i2) + sum[i2, i3) - sum[i3, n + 1)
Here sum[l, r) (1 ≤ l ≤ r ≤ n + 1) uses half-open interval notation: the range includes index l and excludes index r. When l = r, arr[l, r) is empty and sum[l, r) is 0.
Find the maximum gross value of any valid triplet.
n up to 3 * 10^3.sum[i1, i2), repeating the second term. That candidate's own summary and another report's copy of the formula both make it sum[1, i1), which is what the statement above uses. If you get this prompt, check which the formula says.| Approach | Notes |
|---|---|
| Enumerate every triplet of cuts with prefix and suffix sums | O(n^3). The first poster reports it passed about 60% of the tests with n up to 3 * 10^3. |
| Fix the middle cut and scan both sides | O(n^2): for each middle cut, scan every first cut to its left and every third cut to its right. Posted in a second report's summary of the OA problems; no pass rate is given. |
| Fix the middle cut with precomputed prefix maximum and suffix minimum | O(n) after O(n) preprocessing. Given in a reply to the first report, and confirmed by the poster. |
Common mistakes: Stopping at the O(n^3) enumeration of all cuts, which passed about 60% of the tests
What passers do: Fixing the cut between the second and third segments and precomputing the best prefix sum before it and the best suffix sum after it, for O(n) overall (a reply to the first report; another reply says they had just written a version that passed every test)
Why people fail: O(n^3) enumeration of all cuts: about 60% of the tests; Two test cases failing even with a brute force; the candidate suspected the test data
Edge cases probed: Cuts at the same position, leaving a segment empty; Cuts before the first element or after the last, leaving the first or last segment empty
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 62 Citadel questions, refreshed monthly from new candidate reports.