Back to problems

Check anagrams under real-world constraints

Algorithm · Uber · Hard

Implement a function isKAnagram(s, t, k) that returns true when two strings s and t can be turned into anagrams by applying no more than k total single-character insertions or deletions, where an operation may be applied to either string. For k = 0, this reduces to the usual exact anagram check. Describe your solution using these requirements: Give an O(n) algorithm for the exact anagram case and state its time and space complexity. Explain how the method changes when the…

Checking your access…