Sleep Training
Problem
While browsing coding challenges, I came across a task on codingchallenges.fyi that caught my attention. The challenge was to implement a uniq tool, which filters out adjacent duplicate lines in a file, similar to the Unix command-line utility. However, I found it a bit odd that the original uniq requires the input to be sorted to be useful. I decided to take this challenge further by building my own version that supports both sorted and unsorted inputs.
Uniq V2
For my implementation, I decided to keep things simple:
Support for sorted inputs: The tool should work with sorted files, just like the original uniq. No other additional features: The focus is purely on performance and memory optimization.
Solution
To ensure my implementation is efficient, I’ll rely heavily on Go’s benchmarking tools. The following command will help me profile the CPU and memory usage of my solution:
go test -bench=. -benchmem ./uniq -cpuprofile=cpuprofile.out -memprofile=memprofile.out