Skip to content

Add Java Solution for Chewbacca's Digit Inversion Problem #464

@Prathamesh-1011

Description

@Prathamesh-1011

Description:
This issue is for adding a Java solution to solve the problem where Chewbacca wants to minimize a number by inverting some of its digits. Inverting a digit involves replacing it with 9 - t (where t is the original digit), ensuring that the resulting number is the smallest possible positive number and does not contain leading zeros.

Problem Description:
Input: A single integer x (1 ≤ x ≤ 10^18).
Output: The smallest possible number after inverting some digits, without leading zeros.

Constraints:
The input number x can be as large as 10^18, so it needs to be handled as a string or long integer to avoid overflow.
The number should not start with zero after inverting any digits.

Sample Input
4545
Sample Output
4444
Explanation
There are many numbers form after inverting the digit. For minimum number, check if inverting digit is less than or greater than the original digit. If it is less, then invert it otherwise leave it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions