Given an integer, disclude a digit to get the maximum value of the difference.

Problem. Given an integer, disclude a digit to get the maximum value of the difference.
eg.
1
2
3
input/output
12345/1234
12398/1238

Hi, from input, I solved output for cases 1,2,3-digit-numbers but I can't find the relationship between them next ??
Last edited on
For an n-digit number, you only have n possibilities of which digit being removed could produce a maximum difference. Have you tried just brute-forcing it?

Show what you tried in the 1,2,3-digit cases.

- Put another way, what you really need to do is make a function like "int remove_digit(int number, int digit_index)" that removes the digit from the number at the given digit_index.
Then, you loop over this function from the first digit to the last digit, and see which one produces a maximum difference.
- You can do this the hard way, using base-10 manipulate with a combination of for loops and % 10 and / 10, or take the easy way out and convert the digit to a string and back.
Last edited on
Topic archived. No new replies allowed.