InterviewBit: Self Permutation Solution
Count number of lettersApproach
Permutation exists if the letter counts in both string are equal
Implementation
1function permuteStrings(A, B) {2 const [countA, countB] = [new Uint8Array(26), new Uint8Array(26)]34 A.split("").forEach(char => countA[char.charCodeAt(0) - "a".charCodeAt(0)]++)5 B.split("").forEach(char => countB[char.charCodeAt(0) - "a".charCodeAt(0)]++)67 for (let i = 0; i < 26; i++) {8 if (countA[i] !== countB[i]) return 09 }1011 return 112}
References
Similar problems
Amazing Subarrays
Palindrome String
Minimum Characters required to make a String Palindromic
Comments
Loading comments...
Tags
interviewbit
string
Apply and earn a $2,500 bonus once you're hired on your first job!
Clients from the Fortune 500 to Silicon Valley startups
Choose your own rate, get paid on time
From hourly, part-time, to full-time positions
Flexible remote working environment
A lot of open JavaScript jobs!!
Fact corner: Referred talent are 5x more likely to pass the Toptal screening process than the average applicant.
Still hesitate? Read HoningJS author's guide on dealing with Toptal interview process.
Next Post
LeetCode: Number of Ways to Split a String
Playing with indexes
Previous Post
LeetCode: Minimum ASCII Delete Sum for Two Strings
Modified version of Longest Common Subsequence problem