Arcade Score Glitch
Preview mode. Log in to edit, run, submit, and save progress.
Arcade Score Glitch
An arcade cabinet stores your current score as a non-negative integer. During a rare scoring glitch, you may choose any two digit positions in the score and swap those two digits once. You are also allowed to skip the swap if swapping would not improve the score. Your task is to determine the largest score that can be displayed after using this glitch at most one time. The number of digits does not change, and every digit already present in the original score must still appear exactly once after the operation. Input Format: You are given an integer currentScore. Output Format: Return the maximum integer score that can be obtained after performing at most one digit swap.
Examples
currentScore = 2736
7236
Explanation: Swap digit 2 at index 0 with digit 7 at index 1. The score becomes 7236, which is the maximum one-swap value.
Approach hint
Start with the simplest clear approach, explain the trade-off, then move toward the cleaner answer.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.