(str1, str2)
| 7 | // O(n) time - where n is the total of chars in str1 |
| 8 | // O(1) space - because at maximum we will have 26 letters in our dictionary |
| 9 | function scramble(str1, str2) { |
| 10 | const frequencies = {}; |
| 11 | |
| 12 | for (const char of str1) { |
| 13 | if (char in frequencies) { |
| 14 | frequencies[char] += 1; |
| 15 | } else { |
| 16 | frequencies[char] = 1; |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | for (const char of str2) { |
| 21 | if (frequencies.hasOwnProperty(char) && frequencies[char] > 0) { |
| 22 | frequencies[char]--; |
| 23 | } else { |
| 24 | return false; |
| 25 | } |
| 26 | } |
| 27 | return true; |
| 28 | } |
nothing calls this directly
no outgoing calls
no test coverage detected