FastPrepLargest Palindromic Number from Available Digits
Problems/Largest Palindromic Number from Available Digits

Largest Palindromic Number from Available Digits

Marshall Wace logoMarshall Wace● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Marshall Wace online assessment. The report gives all the rules for picking digits, the function signature, five examples and a limit on length. We reworded the task in our own way. Our version is about 99% the same as the reported question.

String S contains decimal digits. Use one or more of its digits to form a palindromic number with the greatest possible decimal value.

  • You may reorder the chosen digits and leave other digits unused.
  • You may not use a digit more times than it appears in S.
  • The answer has no leading zero, except that the one-digit number 0 is allowed.

Return the answer as a string. A palindrome reads the same from left to right and right to left.

Function

solution(S: String) → String

Examples

Example 1

S = "8199"return = "989"

Among the possible values 1, 8, 9, 99, 919 and 989, the greatest is 989.

Example 2

S = "39878"return = "898"

Use the two eights as a pair and nine as the centre.

Example 3

S = "00900"return = "9"

Zero pairs cannot become leading zeros, so the greatest valid result is the single nine.

Example 4

S = "000"return = "0"

Only the one-digit zero avoids a leading zero.

Example 5

S = "54321"return = "5"

No pair exists, so choose the largest available single digit.

Constraints

  • 1 <= S.length <= 100000.
  • S contains only digits from 0 through 9.

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
  • Reconstruct a Two-Row Binary MatrixOA · Seen Apr 2024

Similar questions at other companies

  • Maximize Palindromic WordsSquarepoint Capital · OASquarepoint Capital interview questions
  • Viral Content BalancerTikTok · OATikTok interview questions
  • Find Minimum Time RequiredAmazon · OA
  • Merging PalindromesOld Mission · OA
  • Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
  • Minimum Substrings Without Repeating CharactersMicrosoft · OAMicrosoft interview questions
  • Find Length of Longest Good SubsequenceWalmart · OAWalmart interview questions
  • Reorderable Task Scheduler With CooldownWaymo · PHONE SCREENWaymo interview questions
  • Rearrange a String So No Neighbors MatchThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions
  • Longest-Match Tokenizer with Unknown SymbolsAnthropic · ONSITE INTERVIEWAnthropic 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(String S) {
        // Write your solution here.
    }
}
Checking account…