Created
March 15, 2023 11:37
-
-
Save Ankit-Slnk/a8f5646cc93bc35073bdc03a281faa9c to your computer and use it in GitHub Desktop.
Interview question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String packageNames = "cat,dog,cat,cow"; | |
var map = Map<String, int>(); | |
List<String> ps = []; | |
packageNames.split(",").forEach((element) { | |
if (!map.containsKey(element)) { | |
map[element] = 1; | |
} else { | |
map[element] = map[element]! + 1; | |
} | |
}); | |
map.forEach((String k, int v) { | |
ps.add(k + "($v)"); | |
}); | |
print(map); | |
print(ps.join(",")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment