Loading [MathJax]/jax/output/HTML-CSS/jax.js
[InterviewBit] Self Permutation

Self Permutation

  • Time : O(n)
  • Space : O(n)
c++
1
2
3
4
5
6
7
8
int Solution::permuteStrings(string A, string B) {
if(A.length() != B.length()) return 0;
unordered_map<char, int> freq;
for(auto a : A) freq[a]++;
for(auto b : B) if(--freq[b] == 0) freq.erase(b);
return freq.empty();
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/16/PS/interviewbit/self-permutation/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.

Related Issues not found

Please contact @SongHayoung to initialize the comment