FastPrepLargest Binary Number by Concatenation

Largest Binary Number by Concatenation

Adobe logoAdobe● MediumFULLTIMEOA
Learn

Problem statement

Given an array binaries of non-empty binary strings, reorder every string exactly once and concatenate them.

Return the lexicographically largest concatenation. Because all candidate concatenations have the same total length and contain only 0 and 1, this is also the largest binary value. Preserve every input character, including leading zeros.

Function

largestBinaryConcatenation(binaries: String[]) → String

Examples

Example 1

binaries = ["10","101","1"]return = "110110"

The order 1, 101, 10 produces 110110. For every adjacent pair, placing the first string before the second gives the larger pairwise concatenation.

Example 2

binaries = ["0","00","1"]return = "1000"

The string 1 must come first. The two zero-only strings commute, and all of their zeros are preserved, so the result is 1000.

Constraints

  • 1 <= binaries.length <= 10^4
  • 1 <= binaries[i].length
  • 1 <= sum of all string lengths <= 10^5
  • Every character is 0 or 1.

More Adobe problems

See Adobe hiring insights
public String largestBinaryConcatenation(String[] binaries) {
    // Write your solution here
}
binaries["10","101","1"]
expected"110110"
Checking account…