Loading...
You are given a list of unique strings genes, where every string has the same length and each character is A, C, G, or T.
Two strings belong to the same mutation group if they differ in exactly one position. Note that group membership is transitive: if a and b are in the same group, and b and c are in the same group, then a and c are in the same group too, even if a and c differ in more than one position.
Return the number of mutation groups formed by genes.
Input: genes = ["AACT","AACA","AATA","TTTT"]
Output: 2
Explanation: "AACT" and "AACA" differ only at the last position, so they are in the same group. "AACA" and "AATA" differ only at the third position, so they are in the same group too, which puts "AACT" and "AATA" in that group by transitivity even though they differ in two positions. "TTTT" differs from every other string in three positions, so it forms its own group. That makes 2 groups in total.
Input: genes = ["ACGT","TGCA"]
Output: 2
Explanation: "ACGT" and "TGCA" differ in all four positions, so they are not connected. Each string forms its own group.
genes.length ≤104genes[i].length ≤20genes has the same length.genes is unique.genes[i] is A, C, G, or T.