Problem Statement
Given a list of words, sort them according the the following criteria, and return the sorted list of words.
We define the "first absolute difference" of the string to be the absolute values of the difference of the adjacent character values when the characters are converted to the same case.
fd[i] = |lowercase(st[i])-lowercase(st[i+1])|
"AbczZ" yields {1, 1, 23, 0}
Strings where the first absolute difference is lexographically smaller appear earlier in the sorted list than strings with lexographically greater first absolute differences. If the first differences are different lengths, then the shorter is padded with zeros on the right for purposes of comparison.
Considering each string as a binary number where an upper case character is a '1' and a lower case character is a '0'
the one with the lowest binary value is first.
If all else fails, the reverse of the two strings are compared and the lexographically larger (ignoring case) goes first.
Definition
- Class:
- GoofySort
- Method:
- sort
- Parameters:
- String[]
- Returns:
- String[]
- Method signature:
- String[] sort(String[] word)
- (be sure your method is public)
Constraints
Examples
No public sample cases were explicitly marked for this problem in the original data.