3 ms·
Your anger is misplaced. Characters can repeat, so a boolean array doesn't work. Plus, the story says I mumbled awhile that given the characters were limited
by nl 16y ago
Your anger is misplaced.
Characters can repeat, so a boolean array doesn't work.
Plus, the story says I mumbled awhile that given the characters were limited to alphabetic (his original specification) that I could use an array instead of a hashtable for some constant time savings but that was about it.
- exit 16y agosorry, i don't get how characters repeating affects things
- tedunangst 16y agoIf there are 3 As in the first string and 4 in the second, it fails. A boolean value can't count to 3.
- jamesaguilar 16y agoMaybe in a different problem it would fail, but this is merely a presence test, so booleans are fine. At any rate, an array of int32s instead of bools would defeat the objection for reasonably long strings.
- tedunangst 16y agoThis is that different problem. The author's description is muddy, but you do need the counts.
- bfung 16y agoit doesn't matter if characters are repeated. Let's assume ascii characters, so 'A' = 65 in decimal. If you make an array, T[], where T[65] = 1 if 'A' exists and 0 if 'A' didn't exist in the first string, you can run through the 2nd string to check if T[65] was true (1) or false (0), telling you if the character in the 2nd string appeared in the first. Same thing as the hashtable. I think that's what was meant by boolean array.
- nl 16y agoI guess it depends how the question is presented. Often it is known as the "Ranson Question" (A set of magazines, a given ransom message: can you make the message from the magazines). In this case the question says find out if all the characters in the smaller string are in the larger string, so yes, I think you are right - the repeats don't matter here.