Minimum value of numbers in char array
I recently ran into this problem in an interview, and I was curious what
the best way to solve it would be. The question is given a char array that
has the ascii characters '0' to '9' make one swap such that the the set of
ascii values in the resultant array forms the lowest possible value. Both
the input array will not have preceding 0s and neither should the
resultant array.
So here is an example: char a[] = {'1','0', '9','7','6'}
The solution: char b[] = { '1','0', '6', '7', '9'}
No comments:
Post a Comment