Modern C++ in Advent of Code: Day 6
On the sixth day of Advent Of Code, we detect sequences of unique characters.
I encourage you to solve it yourself first https://adventofcode.com.
Input
Our input today is a single line, so we take it as a std::string
.
Finding unique substring
We can reformulate the problem slightly. We are trying to find a substring where the frequency of each character is one.
The frequency of characters is something we can keep track of as we iterate over the string, so all we need to do is notice that we have reached a situation where the frequency of each character is one.
As this works for any offset, we can reuse this solution for part two.
Links
The repository with a complete solution (including input parsing) is available here: https://github.com/HappyCerberus/moderncpp-aoc-2022.
I post daily Modern C++ content on Twitter, LinkedIn, Mastodon, Medium and Substack.