FastPrepReconstruct a Two-Row Binary Matrix
Problems/Reconstruct a Two-Row Binary Matrix

Reconstruct a Two-Row Binary Matrix

Marshall Wace logoMarshall Wace● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Marshall Wace online assessment. Any matrix that fits the row sums and column sums is accepted. A row sum larger than the number of columns is valid input, and the answer is then impossible. Our version is about 99% the same as the reported question.

Reconstruct a binary matrix with two rows and N columns. Every entry must be 0 or 1. The upper row must sum to U, the lower row must sum to L, and column k must sum to C[k].

Return the upper row as exactly N characters, followed by a comma and the lower row as exactly N characters. Do not include whitespace. If multiple matrices are valid, you may return any of them. If no matrix satisfies all the sums, return IMPOSSIBLE.

Function

solution(U: int, L: int, C: int[]) → String

Examples

Example 1

U = 3L = 2C = [2,1,1,0,1]return = "11001,10100"

The upper row contains three ones and the lower row contains two. Their column sums are [2,1,1,0,1]. This is one valid result; a different valid allocation is also accepted.

Example 2

U = 2L = 3C = [0,0,1,1,2]return = "IMPOSSIBLE"

The column sums require four ones in total, while the requested row sums require five. No valid matrix exists.

Example 3

U = 2L = 2C = [2,0,2,0]return = "1010,1010"

A column sum of two forces both entries to one, and a column sum of zero forces both entries to zero. Both row sums are two.

Constraints

  • 0 <= U, L <= 100000.
  • N = C.length and 1 <= N <= 100000.
  • 0 <= C[k] <= 2.

More Marshall Wace Online Assessment questions

  • Count Letters with Ordered Lowercase and Uppercase OccurrencesOA · Seen Oct 2025
  • Maximum Trailing Zeros on a Path with at Most One TurnOA · Seen Oct 2025
  • Shortest Subarray Covering an Integer RangeOA · Seen Oct 2025
  • Maximum Events in a 60-Second WindowOA · Seen Aug 2025
  • Successful Logins from Multiple CountriesOA · Seen Aug 2025
  • Maximize Remaining Item Types After Clearing Consecutive ShelvesOA · Seen Nov 2024
  • Shortest String After Erasing Equal PairsOA · Seen Nov 2024
  • Count Distinct Tags in a Fixed-Radius Circle (Practice Reconstruction)OA · Seen Apr 2024
  • Generate Unique Company Email AddressesOA · Seen Apr 2024
  • Crop a Notification at Whole-Word BoundariesOA · Seen Jan 2024

Similar questions at other companies

  • Minimum Operations to Sort with Rotations Then SwapsBank of New York Mellon · OA
  • Minimum Cost of Left and Right PropagationAmazon · OA
  • Minimum Rounds to Complete All TasksInfosys · OAInfosys interview questions
  • Reschedule Meetings for Maximum Free TimeFivetran · OAFivetran interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Maximum ScoreNVIDIA · OANVIDIA interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Minimize Adjacent Squared-Difference Cost with One InsertionMcKinsey & Company · OAMcKinsey & Company interview questions
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions

Interview reports that mention this question

  • Marshall Wace Coding Tests: 11 Experiences (Part 2 of 3)
  • Marshall Wace Quant and Coding OA: 19 Experiences (Part 1 of 3)

Marshall Wace interview experiences

  • Marshall Wace Older Quant Tests: 5 Experiences (Part 3 of 3)
All Marshall Wace interview questionsSee Marshall Wace hiring insights
Saved
class Solution {
    public String solution(int U, int L, int[] C) {
        // Write your solution here.
    }
}
U3
L2
C[2,1,1,0,1]
reference"11001,10100"
Checking account…