1/* Time complexity of solution: O(n) */
2const getRepeatedChars = (str) => {
3 const chars = {};
4 for (const char of str) {
5 chars[char] = (chars[char] || 0) + 1;
6 }
7 return Object.entries(chars).filter(char => char[1] > 1).map(char => char[0]);
8}
9
10getRepeatedChars("aabbkdndiccoekdczufnrz"); // ["a", "b", "c", "d", "k", "n", "z"]