PracHub
QuestionsPremiumLearningGuidesInterview PrepNEWCoaches
|Home/Coding & Algorithms/SoFi

Rearrange array to maximize positive prefix sums

Last updated: May 10, 2026

Quick Overview

This question evaluates array manipulation, prefix-sum reasoning, and greedy/combinatorial optimization skills for maximizing a permutation-based metric in the Coding & Algorithms category.

  • easy
  • SoFi
  • Coding & Algorithms
  • Software Engineer

Rearrange array to maximize positive prefix sums

Company: SoFi

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Take-home Project

## Problem You are given an integer array `a` of length `n`. You may **rearrange** the elements in any order. Define the prefix sums of a permutation `p` as: - `pref[i] = p[0] + p[1] + ... + p[i]` for `0 <= i < n` Let `score(p)` be the number of indices `i` such that `pref[i] > 0`. ### Task Compute the **maximum possible value of** `score(p)` over all permutations `p` of the array. ### Input - Integer array `a` (may contain negative, zero, and positive values). ### Output - An integer: the maximum number of positive prefix sums achievable. ### Constraints - `1 <= n <= 2 * 10^5` - `-10^9 <= a[i] <= 10^9` - Target time complexity: `O(n log n)` (or better). ### Example - Input: `[2, -1, 2, -3]` - One optimal permutation: `[2, 2, -1, -3]` - Prefix sums: `[2, 4, 3, 0]` → positive prefix sums = `3` → Output: `3`

Quick Answer: This question evaluates array manipulation, prefix-sum reasoning, and greedy/combinatorial optimization skills for maximizing a permutation-based metric in the Coding & Algorithms category.

Related Interview Questions

  • Find Smallest Common Row Value - SoFi (easy)
  • Format words into wrapped/justified lines - SoFi (medium)
  • Find the second most frequent tag - SoFi (medium)
  • Implement a multithreaded task executor with semaphores - SoFi (medium)
  • Implement chance of a personal best - SoFi (hard)
SoFi logo
SoFi
Jan 7, 2026, 12:00 AM
Software Engineer
Take-home Project
Coding & Algorithms
8
0
Coding Console
Loading...

Problem

You are given an integer array a of length n. You may rearrange the elements in any order.

Define the prefix sums of a permutation p as:

  • pref[i] = p[0] + p[1] + ... + p[i] for 0 <= i < n

Let score(p) be the number of indices i such that pref[i] > 0.

Task

Compute the maximum possible value of score(p) over all permutations p of the array.

Input

  • Integer array a (may contain negative, zero, and positive values).

Output

  • An integer: the maximum number of positive prefix sums achievable.

Constraints

  • 1 <= n <= 2 * 10^5
  • -10^9 <= a[i] <= 10^9
  • Target time complexity: O(n log n) (or better).

Example

  • Input: [2, -1, 2, -3]
  • One optimal permutation: [2, 2, -1, -3]
  • Prefix sums: [2, 4, 3, 0] → positive prefix sums = 3 → Output: 3

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More SoFi•More Software Engineer•SoFi Software Engineer•SoFi 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.