Tag: parity

Find the largest number by swapping adjacent digits if they have the same parity in Swift

Problem description: You are given a number. You can swap two adjacent digits, if they are both odd or even. For e.g. given (3,8), you can’t swap them. But you can swap (5,9) since they are both odd. They have the same parity. A similar problem is explained here https://www.youtube.com/watch?v=qEIGhVtZ-sg Function description: swapDigitsAndGetLargestNumber(number: String) Returns:

Continue Reading →