Imagine a file in the following fixed format:
<url><white_space><long value>
Example:
http://api.tech.com/item/121345 9
http://api.tech.com/item/122345 350
http://api.tech.com/item/123345 25
http://api.tech.com/item/124345 231
http://api.tech.com/item/125345 111
...
Write a program that reads from stdin the absolute path of a file in the above format and outputs a list of the URLs associated with the 10 largest values in the right-most column.
For instance, for the above example and N=2, the output would be:
http://api.tech.com/item/122345
http://api.tech.com/item/124345
- Must work efficiently with extremely large files (e.g., billions of lines).
- Should use concurrency or stream processing to handle memory constraints.
- Output should only include the top 10 URLs based on value.
- The file is newline-delimited and each line contains a URL followed by a numeric value separated by whitespace.
- We assume valid input and no missing values.
go run main.go /path/to/data.txt- Correctness and output accuracy.
- Efficient memory and CPU use.
- Concurrency usage.
- Clean and well-documented code.
Please install and run a linter on your code before submission.
We recommend using golangci-lint (a popular all-in-one Go linter).
golangci-lint run ./...Make sure your code is free of linting errors and warnings before submitting.
Good luck! 🦾