Created
July 1, 2018 01:24
island count follow up No. 1
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
Follow-up 1: | |
Let's say the dataset is very large. | |
The input data is now a list of coordinates for any piece of land. | |
No guarantee on order of coordinates given to you. (random order) | |
(1000, 23) | |
(0, 1) | |
(0, 3)(3948, 1837) | |
Julia's analysis: | |
size k -> preprocessing size k -> order by sort by row, second col (added after mock interview, I did say that | |
it is not necessary) | |
put all cordination into dictionary to loop up O(1) <- | |
key = row + ';' + col -> 1 -> value 1's dictionary -> O(1) | |
visited one -> look up hashset O(1) | |
1st loop: insert all into land_dictionary | |
2nd loop: lookup neighbors in land_dcitionary and mark in visisted dictionary | |
returning number of island at the very end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment