DEV Community

loading...
Play Button Pause Button

Common Character Count!!Swift Coding Challenge!!

thetealpickle profile image creator ใƒป1 min read

Swift coding challenge!!
Common Character Count, given two strings find the number of common characters between them.

๐Ÿ˜› Level: Easy ๐Ÿ˜›

I have included a solutions video!! The video gives some insight into how Iโ€™ve solved the problem. Donโ€™t forget to try the problem out BEFORE checking out the solution video and solution code ๐Ÿ˜‰ ๐Ÿ˜‰

If you have a coding challenge you want me to solve feel free to drop a comment or message me with the problem!! ๐Ÿ˜Š ๐Ÿ˜Š letโ€™s get swole ๐Ÿ’ช๐Ÿพ ๐Ÿ’ป ๐Ÿ’ป

Discussion (2)

pic
Editor guide
Collapse
gualtierofr profile image
Gualtiero Frigerio

If I was given this question during an interview I'd have asked for clarification, as to me there are 2 common characters between the two strings: a and c. Why do I need to count a 2 times?
Under your assumption, the code you posted is correct and I think it is the easiest.
Only a little detail: characters is deprecated and you can iterate through the string by writing
for char in string {
...
}

Collapse
thetealpickle profile image
creator Author

Thanks for the tip about characters ๐Ÿ‘, I didn't realize it was deprecated. Back to for loops ๐Ÿ˜