Problems with TMap

i don’t understand how > for (auto Letter : Word) can loop through letters and how > if (LetterSeen[Letter]) can compare the letters

1 Like
for (auto Letter : Word)

this essentially means “for each Letter in the Word”

auto just lets the program automatically determine that Letter is a char, rather than you having to write char yourself

if (LetterSeen[Letter])

LetterSeen is a lookup table, so if Letter is 'A' it looks to see if LetterSeen table already has an entry for A. If so then you’ve got a duplicate

eg for AMBULANCE, LetterSeen['A'] is set true for the first character, and then when you get to the sixth character, LetterSeen['A'] will already be true, hence you have a duplicate letter A, and can exit the loop, reporting that it is not an ISOGRAM

LetterSeen TMAP
==========================
Letter       |        Seen
--------------------------
A              |      True  <= Already True, so can't have another 'A'
B              |      True
C              |      True
D              |
E              |
F              |
G              |
...
...
L              |      True
M              |      True
N              |      True

etc

2 Likes

Privacy & Terms