diff --git a/interview/.gitignore b/interview/.gitignore new file mode 100644 index 0000000..9efceb8 --- /dev/null +++ b/interview/.gitignore @@ -0,0 +1,2 @@ +numbers.txt +out.txt diff --git a/interview/generate_numbers.py b/interview/generate_numbers.py index 4c3faab..eac775b 100644 --- a/interview/generate_numbers.py +++ b/interview/generate_numbers.py @@ -6,7 +6,7 @@ def main(): - numbers = random.sample(range(9999999), 100) + numbers = random.sample(range(9999999), 1000000) open("numbers.txt", "w")\ .write("\n".join(str(n) for n in numbers)) diff --git a/interview/sorting_linear.py b/interview/sorting_linear.py index 4a986bf..8d09f63 100644 --- a/interview/sorting_linear.py +++ b/interview/sorting_linear.py @@ -1,4 +1,6 @@ """ +Task: + Implement an algorithm to sort 1,000,000 32-bit integers, using only 350K of memory. The numbers could be any number from 0 to 9,999,999 The numbers are in a file, one line per number. There are no duplicates. @@ -31,6 +33,7 @@ def get_sorted_numbers(self): yield base + j +@profile def main(): bitsorter = Bitsort(9999999) @@ -38,7 +41,7 @@ def main(): for line in in_file: bitsorter.save_number(int(line.rstrip())) - out_file = open("out.txt", "w") + out_file = open("out.txt", "w", 4096) for number in bitsorter.get_sorted_numbers(): out_file.write(str(number) + "\n")