Skip to content

Random coding challenges and my attempt at solving them

License

Notifications You must be signed in to change notification settings

stamoun/CodingChallenges

Repository files navigation

CodingChallenges

Random coding challenges and my attempt at solving them

Build status

1. Next Biggest Number

Rules

  1. Given a number, find the next possible biggest number by reusing the number's digits.
Input Output
12 21
122 212
1234 1243
2017 2071
2071 2107
1234 1243
63842 64238
218765 251678
534976 536479
  1. When a number does not have any next possible number, it returns -1 (e.g. 441 returns -1)

  2. Invalid input strings throw an ArgumentException

Solution #1

Insert, Shift, Sort

  1. Start at the lowest value (lowDigit)
    • 534976
  2. Iterate through the upper digits (highDigit)
  3. If lowDigit > highDigit, insert lowDigit at highDigit index
    • 534976 becomes 536497
  4. Take the lowermost part before the swap and sort them in ascending order
    • 536479

Solution 1

About

Random coding challenges and my attempt at solving them

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages