Bird
Raised Fist0

Given the input list [9, 91, 90], what is the output of the largest number formation algorithm that sorts numbers as strings with a custom comparator?

easy🧾 Trace Q3 of Q15
Greedy Algorithms - Largest Number (Arrange to Form Biggest)
Given the input list [9, 91, 90], what is the output of the largest number formation algorithm that sorts numbers as strings with a custom comparator?
A"99190"
B"91990"
C"99910"
D"90919"
Step-by-Step Solution
Solution:
  1. Step 1: Convert numbers to strings

    Strings: "9", "91", "90"
  2. Step 2: Compare pairs using concatenation

    Compare "9"+"91" = "991" vs "91"+"9" = "919"; "991" > "919", so "9" > "91"
  3. Step 3: Compare "91" and "90"

    "91"+"90" = "9190" vs "90"+"91" = "9091"; "9190" > "9091", so "91" > "90"
  4. Step 4: Sorted order is ["9", "91", "90"]

    Concatenate to get "99190"
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Concatenation comparisons confirm order [OK]
Quick Trick: Compare xy and yx concatenations to decide order [OK]
Common Mistakes:
MISTAKES
  • Sorting numerically descending ignoring concatenation
  • Assuming longer strings always come first
  • Mixing up concatenation order in comparisons
Trap Explanation:
PITFALL
  • Ignoring concatenation order leads to incorrect output.
Interviewer Note:
CONTEXT
  • Tests ability to trace the sorting logic step-by-step.
Master "Largest Number (Arrange to Form Biggest)" in Greedy Algorithms

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Greedy Algorithms Quizzes