PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates a candidate's algorithmic problem-solving skills across array and time-series processing, greedy optimization, and dynamic programming, requiring implementation and complexity analysis of maximum drawdown, single-trade profit, and coin change problems within the Coding & Algorithms domain for a Data Scientist role.

  • Medium
  • Squarepoint Capital
  • Coding & Algorithms
  • Data Scientist

Implement drawdown, single-trade profit, coin change

Company: Squarepoint Capital

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

Implement and analyze the following three problems: 1) Maximum drawdown of cumulative PnL: "What is the maximum drawdown of a cumulative PnL (profit and loss) series, and when did it occur?" Write mdd(pnl) that returns: (a) the maximum drawdown as a negative number; (b) the start index (just after the peak before the drawdown starts); and (c) the end index (where the maximum drawdown ends). State time and space complexity. 2) Single-trade stock profit (LeetCode-inspired): Given an integer array prices where prices[i] is the price on day i, compute the largest profit achievable by buying once and selling on a later day. If no profitable trade exists, return 0. Design an O (n) time, O( 1) space solution and explain the intuition. 3) Minimum coins for target amount (LeetCode-inspired): Given coin denominations coins and a target amount, return the smallest number of coins needed to reach the target, or -1 if it cannot be formed. Assume unlimited coins of each type. Provide a dynamic programming approach and analyze time and space.

Quick Answer: This question evaluates a candidate's algorithmic problem-solving skills across array and time-series processing, greedy optimization, and dynamic programming, requiring implementation and complexity analysis of maximum drawdown, single-trade profit, and coin change problems within the Coding & Algorithms domain for a Data Scientist role.

Maximum Drawdown of a Cumulative PnL Series

You are given an array `pnl` where `pnl[i]` is the cumulative profit-and-loss of a trading strategy at time step `i`. The **drawdown** at any point is the drop from the running maximum (peak) seen so far down to the current value. The **maximum drawdown** is the largest such drop over the whole series. Implement `mdd(pnl)` that returns a tuple `(max_drawdown, start_index, end_index)` where: - `max_drawdown` is the maximum drawdown expressed as a **negative number** (the value at the trough minus the value at the preceding peak). If the series never declines below its running peak, the drawdown is `0`. - `start_index` is the index of the peak that immediately precedes the worst drawdown. - `end_index` is the index of the trough where the worst drawdown is realized. For an empty input, return `(0, -1, -1)`. State the time and space complexity. **Example:** `pnl = [0, 5, 3, 8, 2, 6, 1]`. The running peak reaches `8` at index 3, and the series falls to `1` at index 6, giving a drawdown of `1 - 8 = -7`. Answer: `(-7, 3, 6)`.

Constraints

  • 0 <= len(pnl) <= 10^5
  • -10^9 <= pnl[i] <= 10^9
  • Drawdown is measured relative to the running maximum (peak) seen so far.
  • If the series never falls below its running peak, the drawdown is 0.

Examples

Input: ([0, 5, 3, 8, 2, 6, 1],)

Expected Output: (-7, 3, 6)

Explanation: Running peak hits 8 at index 3; series bottoms at 1 (index 6): 1 - 8 = -7.

Input: ([1, 2, 3, 4, 5],)

Expected Output: (0, 0, 0)

Explanation: Monotonically increasing series never dips below its running peak, so drawdown is 0.

Input: ([5, 4, 3, 2, 1],)

Expected Output: (-4, 0, 4)

Explanation: Peak is 5 at index 0; trough is 1 at index 4: 1 - 5 = -4.

Input: ([],)

Expected Output: (0, -1, -1)

Explanation: Empty series: defined to return (0, -1, -1).

Input: ([10],)

Expected Output: (0, 0, 0)

Explanation: Single point cannot draw down from itself.

Input: ([3, 1, 4, 1, 5, 9, 2, 6],)

Expected Output: (-7, 5, 6)

Explanation: Peak 9 at index 5, then 2 at index 6: 2 - 9 = -7, the worst single drop.

Hints

  1. Sweep once from left to right, tracking the highest cumulative PnL (and its index) seen so far.
  2. At each step the current drawdown is value - runningPeak; remember the peak's index so you can report where the drop began.
  3. Keep the most negative drawdown observed along with the peak index that produced it and the current index as the trough.

Best Time to Buy and Sell Stock (Single Trade)

You are given an integer array `prices` where `prices[i]` is the price of a given stock on day `i`. You want to maximize your profit by choosing a single day to **buy** one stock and choosing a different day **in the future** to **sell** that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return `0`. Design an **O(n) time, O(1) space** solution. **Example:** `prices = [7, 1, 5, 3, 6, 4]`. Buy on day 1 (price 1) and sell on day 4 (price 6) for a profit of `6 - 1 = 5`.

Constraints

  • 0 <= len(prices) <= 10^5
  • 0 <= prices[i] <= 10^4
  • You must buy before you sell (buy day strictly before sell day).
  • Only a single buy/sell transaction is allowed.

Examples

Input: ([7, 1, 5, 3, 6, 4],)

Expected Output: 5

Explanation: Buy at 1 (day 1), sell at 6 (day 4): profit 5.

Input: ([7, 6, 4, 3, 1],)

Expected Output: 0

Explanation: Prices only fall; no profitable trade, so return 0.

Input: ([1, 2, 3, 4, 5],)

Expected Output: 4

Explanation: Buy at 1, sell at 5: profit 4.

Input: ([],)

Expected Output: 0

Explanation: Empty input: no trade possible.

Input: ([5],)

Expected Output: 0

Explanation: Only one day; cannot buy and sell on different days.

Input: ([2, 2, 2, 2],)

Expected Output: 0

Explanation: Flat prices yield no profit.

Input: ([3, 8, 1, 9],)

Expected Output: 8

Explanation: Buy at 1 (day 2), sell at 9 (day 3): profit 8, which beats 8 - 3 = 5.

Hints

  1. As you scan left to right, track the lowest price seen so far — that is the best day to have bought before today.
  2. At each day, the best profit if you sold today is price - minSoFar; keep the maximum across all days.
  3. If prices only ever fall, the running best profit stays 0, which is the correct answer.

Coin Change (Minimum Coins)

You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money. Return the **fewest number of coins** that you need to make up that amount. If that amount of money cannot be made up by any combination of the coins, return `-1`. You may assume that you have an **infinite** number of each kind of coin. Provide a dynamic-programming approach and analyze its time and space complexity. **Example:** `coins = [1, 2, 5]`, `amount = 11`. The answer is `3` because `11 = 5 + 5 + 1`.

Constraints

  • 1 <= len(coins) <= 12
  • 1 <= coins[i] <= 2^31 - 1
  • 0 <= amount <= 10^4
  • Unlimited supply of each coin denomination.

Examples

Input: ([1, 2, 5], 11)

Expected Output: 3

Explanation: 11 = 5 + 5 + 1 uses 3 coins, the minimum.

Input: ([2], 3)

Expected Output: -1

Explanation: Odd target with only a coin of 2 is impossible.

Input: ([1], 0)

Expected Output: 0

Explanation: Amount 0 needs no coins.

Input: ([2, 5, 10, 1], 27)

Expected Output: 4

Explanation: 27 = 10 + 10 + 5 + 2 uses 4 coins.

Input: ([186, 419, 83, 408], 6249)

Expected Output: 20

Explanation: Greedy fails here; DP finds 20 coins as the true minimum.

Input: ([5], 5)

Expected Output: 1

Explanation: A single coin of 5 makes 5.

Input: ([7, 11], 1)

Expected Output: -1

Explanation: No combination of 7 and 11 forms 1.

Hints

  1. Let dp[a] = the minimum number of coins to form amount a; dp[0] = 0.
  2. For each amount a, try every coin c <= a and relax dp[a] = min(dp[a], dp[a - c] + 1).
  3. Initialize unreachable amounts to a sentinel (e.g. amount + 1); if dp[amount] is still the sentinel at the end, return -1.
Last updated: Jun 25, 2026

Related Coding Questions

  • Compute drawdown, profit, and coin change - Squarepoint Capital (Medium)

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.