Skip to content

Instantly share code, notes, and snippets.

@anish000kumar
Last active December 7, 2020 16:34
Show Gist options
  • Save anish000kumar/351205732106170aa25da6f9bf59f76c to your computer and use it in GitHub Desktop.
Save anish000kumar/351205732106170aa25da6f9bf59f76c to your computer and use it in GitHub Desktop.
coordinate compression
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