PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Goldman Sachs

Count segments and optimize 3-server assignment

Last updated: Mar 29, 2026

Quick Overview

This two-part problem evaluates array-processing and counting competency for identifying fixed-length strictly increasing subarrays and combinatorial partitioning and optimization competency for assigning elements to three groups to maximize a minimal pairwise-difference metric, and is commonly asked to assess efficient algorithm design, correctness under constraints, and the ability to handle large inputs. Belonging to the Coding & Algorithms domain, it tests practical algorithmic application, data-structure-aware implementation and complexity analysis rather than purely theoretical understanding.

  • medium
  • Goldman Sachs
  • Coding & Algorithms
  • Software Engineer

Count segments and optimize 3-server assignment

Company: Goldman Sachs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

There are two independent programming tasks. --- ### Problem 1: Transaction Segments You are given: - An integer `n`, the length of an array. - An integer `k` (1 ≤ k ≤ n). - An integer array `transactionValues` of length `n`, where `transactionValues[i]` represents the transaction amount at time `i` (0-based index). A **contiguous segment** `transactionValues[l..r]` (where `0 ≤ l ≤ r < n`) is called **strictly increasing** if: - For every `i` with `l ≤ i < r`, we have `transactionValues[i] < transactionValues[i + 1]`. Your task is to **count how many contiguous subarrays of length exactly `k` are strictly increasing**. Formally, count the number of starting indices `s` such that: - `0 ≤ s ≤ n - k`, and - `transactionValues[s] < transactionValues[s + 1] < ... < transactionValues[s + k - 1]`. **Input** - `n`, `k` - Array `transactionValues[0..n-1]` **Output** - A single integer: the number of strictly increasing contiguous subarrays of length exactly `k`. Design an algorithm that runs efficiently for large `n` (e.g., up to around 2 × 10^5). --- ### Problem 2: Efficient Tasks Across 3 Servers You are given: - An integer `n` (n ≥ 3), the number of software modules. - An integer array `difficulty` of length `n`, where `difficulty[i]` is the difficulty of the `i`-th software module. You must assign all modules to **3 servers** subject to: - Each server must receive **at least one** module. - Every module must be assigned to **exactly one** server. After a particular assignment (partition) of modules into 3 non-empty groups `S1`, `S2`, and `S3` (one group per server) is fixed, you are allowed to choose **one module** from each server: - Choose index `i1 ∈ S1` with difficulty `d1 = difficulty[i1]`. - Choose index `i2 ∈ S2` with difficulty `d2 = difficulty[i2]`. - Choose index `i3 ∈ S3` with difficulty `d3 = difficulty[i3]`. For this assignment, define the value: \[ F(S_1,S_2,S_3) = \min_{i_1 \in S_1,\ i_2 \in S_2,\ i_3 \in S_3} \bigl(|d_1 - d_2| + |d_2 - d_3|\bigr) \] That is, for the given partition of modules into three servers, you choose one module from each server so that the expression \(|d1 - d2| + |d2 - d3|\) is as **small as possible**, and that minimal value is \(F\) for this partition. Your overall goal is to choose an assignment of modules to the three servers that **maximizes** this minimal value. In other words, over all valid partitions `(S1, S2, S3)` of the modules into three non-empty, disjoint sets whose union is all modules, compute: \[ \max_{(S_1,S_2,S_3)} F(S_1,S_2,S_3) \] and output this maximum. **Input** - `n` - Array `difficulty[0..n-1]` **Output** - A single integer: the maximum possible value of \(F(S_1,S_2,S_3)\) over all valid assignments. Design an algorithm that is significantly more efficient than enumerating all possible assignments (which is exponential in `n`) and can handle large `n` (e.g., up to around 2 × 10^5).

Quick Answer: This two-part problem evaluates array-processing and counting competency for identifying fixed-length strictly increasing subarrays and combinatorial partitioning and optimization competency for assigning elements to three groups to maximize a minimal pairwise-difference metric, and is commonly asked to assess efficient algorithm design, correctness under constraints, and the ability to handle large inputs. Belonging to the Coding & Algorithms domain, it tests practical algorithmic application, data-structure-aware implementation and complexity analysis rather than purely theoretical understanding.

Related Interview Questions

  • Implement an Integer Hash Map - Goldman Sachs
  • Solve string and hashmap coding tasks - Goldman Sachs (medium)
  • Find first non-repeating character index - Goldman Sachs (nan)
  • Solve string and hashmap interview tasks - Goldman Sachs (medium)
  • Complete decision tree and gradient descent functions - Goldman Sachs (hard)
Goldman Sachs logo
Goldman Sachs
Dec 7, 2025, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
6
0

There are two independent programming tasks.

Problem 1: Transaction Segments

You are given:

  • An integer n , the length of an array.
  • An integer k (1 ≤ k ≤ n).
  • An integer array transactionValues of length n , where transactionValues[i] represents the transaction amount at time i (0-based index).

A contiguous segment transactionValues[l..r] (where 0 ≤ l ≤ r < n) is called strictly increasing if:

  • For every i with l ≤ i < r , we have transactionValues[i] < transactionValues[i + 1] .

Your task is to count how many contiguous subarrays of length exactly k are strictly increasing.

Formally, count the number of starting indices s such that:

  • 0 ≤ s ≤ n - k , and
  • transactionValues[s] < transactionValues[s + 1] < ... < transactionValues[s + k - 1] .

Input

  • n , k
  • Array transactionValues[0..n-1]

Output

  • A single integer: the number of strictly increasing contiguous subarrays of length exactly k .

Design an algorithm that runs efficiently for large n (e.g., up to around 2 × 10^5).

Problem 2: Efficient Tasks Across 3 Servers

You are given:

  • An integer n (n ≥ 3), the number of software modules.
  • An integer array difficulty of length n , where difficulty[i] is the difficulty of the i -th software module.

You must assign all modules to 3 servers subject to:

  • Each server must receive at least one module.
  • Every module must be assigned to exactly one server.

After a particular assignment (partition) of modules into 3 non-empty groups S1, S2, and S3 (one group per server) is fixed, you are allowed to choose one module from each server:

  • Choose index i1 ∈ S1 with difficulty d1 = difficulty[i1] .
  • Choose index i2 ∈ S2 with difficulty d2 = difficulty[i2] .
  • Choose index i3 ∈ S3 with difficulty d3 = difficulty[i3] .

For this assignment, define the value:

F(S1,S2,S3)=min⁡i1∈S1, i2∈S2, i3∈S3(∣d1−d2∣+∣d2−d3∣)F(S_1,S_2,S_3) = \min_{i_1 \in S_1,\ i_2 \in S_2,\ i_3 \in S_3} \bigl(|d_1 - d_2| + |d_2 - d_3|\bigr)F(S1​,S2​,S3​)=mini1​∈S1​, i2​∈S2​, i3​∈S3​​(∣d1​−d2​∣+∣d2​−d3​∣)

That is, for the given partition of modules into three servers, you choose one module from each server so that the expression ∣d1−d2∣+∣d2−d3∣|d1 - d2| + |d2 - d3|∣d1−d2∣+∣d2−d3∣ is as small as possible, and that minimal value is FFF for this partition.

Your overall goal is to choose an assignment of modules to the three servers that maximizes this minimal value.

In other words, over all valid partitions (S1, S2, S3) of the modules into three non-empty, disjoint sets whose union is all modules, compute:

max⁡(S1,S2,S3)F(S1,S2,S3)\max_{(S_1,S_2,S_3)} F(S_1,S_2,S_3)max(S1​,S2​,S3​)​F(S1​,S2​,S3​)

and output this maximum.

Input

  • n
  • Array difficulty[0..n-1]

Output

  • A single integer: the maximum possible value of F(S1,S2,S3)F(S_1,S_2,S_3)F(S1​,S2​,S3​) over all valid assignments.

Design an algorithm that is significantly more efficient than enumerating all possible assignments (which is exponential in n) and can handle large n (e.g., up to around 2 × 10^5).

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Goldman Sachs•More Software Engineer•Goldman Sachs Software Engineer•Goldman Sachs Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.