// This is my second solution, c.f. https://github.com/annabunches/adventofcode/commit/3ca1a1068b749bab4d0626af32549ce2385d57bb // for the original solution. // // This solution is far more elegant; it runs in O(n*m) time, instead of the original implementation's O(n^2 * m) time. // Thanks to @lizthegrey for (probably unintentionally) prompting me to rewrite this >_> package main import ( "fmt" "internal/util" ) func main() { ids := util.ReadInput() subIDs := make(map[string]struct{}) for _, id := range ids { // iterate over each letter for i := range id { // create a subID with just letter id[i] omitted subID := id[0:i] + id[i+1:] // if it's already in our map, we've found the correct output if _, found := subIDs[subID]; found { fmt.Println(subID) return } // otherwise, add the substring to our map subIDs[subID] = struct{}{} } } }