Last active
December 7, 2020 16:34
-
-
Save anish000kumar/351205732106170aa25da6f9bf59f76c to your computer and use it in GitHub Desktop.
coordinate compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compress(arr): | |
arr.sort(); | |
compress_map = {} | |
val = 1 | |
for el in arr: | |
if el not in compress_map: | |
compress_map[el] = val | |
val += 1 | |
for i in range(len(arr)): | |
arr[i] = compress_map[ arr[i] ] | |
return (arr, compress_map) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment