Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
package groups_of_special_equivalent_strings

func numSpecialEquivGroups(A []string) int {
m := make(map[[52]int]bool)
for _, s := range A {
var count [52]int
for i, char := range s {
count[int(char)-'a'+26*(i%2)]++
}
m[count] = true
}
return len(m)
}
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
package groups_of_special_equivalent_strings

import "testing"

type caseType struct {
input []string
expected int
}

func TestNumSpecialEquivGroups(t *testing.T) {
tests := [...]caseType{
{
input: []string{"a", "b", "c", "a", "c", "c"},
expected: 3,
},
{
input: []string{"aa", "bb", "ab", "ba"},
expected: 4,
},
{
input: []string{"abc", "acb", "bac", "bca", "cab", "cba"},
expected: 3,
},
{
input: []string{"abcd", "cdab", "adcb", "cbad"},
expected: 1,
},
}
for _, tc := range tests {
output := numSpecialEquivGroups(tc.input)
if output != tc.expected {
t.Fatalf("input: %v, output: %v, expected: %v", tc.input, output, tc.expected)
}
}
}