Given two strings of lowercase alphabets and a value K, your task is to complete the given function which tells if  two strings are K-anagrams of each other or not.
Two strings are called K-anagrams if both of the below conditions are true.
1. Both have same number of characters.
2. Two strings can become anagram by changing at most K characters in a string.
Example:
Input:
str1 = "fodr", str2="gork"
k = 2
Output:
1
Explanation: Can change fd to gk
Your Task:
Since this is a function problem, you don't need to take any input. Just complete the given function areKAnagrams that returns true if the strings can be turned into K-anagrams, else return false.
Constraints:
1 ≤ length of String ≤ 10^{5}
1 ≤ K ≤ length of String

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function template for Python 3



class Solution:

    def areKAnagrams(self, str1, str2, k):

        # code here

Solutions:
class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) == len(str2):
			x = 0
			from collections import Counter
			d = Counter(str1)
			for i in str2:
				if d[i] > 0:
					x = x + 1
					d[i] -= 1
			if len(str2) - x <= k:
				return True
			else:
				return False
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		freq_str1 = {}
		freq_str2 = {}
		for i in str1:
			freq_str1[i] = freq_str1.get(i, 0) + 1
		for j in str2:
			freq_str2[j] = freq_str2.get(j, 0) + 1
		diff = 0
		for m in str2:
			if m not in freq_str1 or freq_str1[m] == 0:
				diff += 1
			else:
				freq_str1[m] -= 1
		if diff <= k:
			return True
		else:
			return False


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		else:
			x = Counter(str1)
			for j in str2:
				if j in x and x[j] > 0:
					x[j] = x[j] - 1
			c = 0
			for r in x:
				c = c + x[r]
			if c <= k:
				return True
			else:
				return False


from collections import defaultdict

class Solution:

	def areKAnagrams(self, str1, str2, k):
		mp1 = defaultdict(int)
		mp2 = defaultdict(int)
		for i in str1:
			mp1[i] += 1
			mp2[i] += 0
		for i in str2:
			mp1[i] += 0
			mp2[i] += 1
		cnt1 = 0
		cnt2 = 0
		for i in mp1:
			if mp1[i] >= mp2[i]:
				cnt1 += mp1[i] - mp2[i]
			else:
				cnt2 += mp2[i] - mp1[i]
		if cnt1 == cnt2 <= k:
			return True
		return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		c = 0
		if len(str1) == len(str2):
			for i in str1:
				if i not in str2:
					c += 1
				else:
					str2 = str2.replace(i, '', 1)
			if c <= k:
				return True
			else:
				return False
		return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		dict1 = {}
		dict2 = {}
		for i in str1:
			if i in dict1:
				dict1[i] += 1
			else:
				dict1[i] = 1
		for i in str2:
			if i in dict2:
				dict2[i] += 1
			else:
				dict2[i] = 1
		res = 0
		for i in dict1:
			if i not in dict2:
				res += dict1[i]
			elif dict1[i] > dict2[i]:
				res += dict1[i] - dict2[i]
		if res <= k:
			return True
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		d1 = {}
		d2 = {}
		count = 0
		for i in str1:
			d1[i] = d1.get(i, 0) + 1
		for j in str2:
			d2[j] = d2.get(j, 0) + 1
		for i in d1:
			if i in d2 and d1[i] == d2[i]:
				continue
			elif i in d2 and d1[i] > d2[i]:
				count += d1[i] - d2[i]
			elif i not in d2:
				count += d1[i]
		if count <= k:
			return True
		else:
			return False


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return 0
		dict1 = Counter(str1)
		dict2 = Counter(str2)
		c = 0
		for (key, value) in dict1.items():
			if key in dict2 and value > dict2[key]:
				c += value - dict2[key]
			elif key not in dict2:
				c += value
		if k >= c:
			return 1
		return 0


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		dict1 = Counter(str1)
		dict2 = Counter(str2)
		res = 0
		for (key, value) in dict1.items():
			if key in dict2 and value > dict2[key]:
				k -= value - dict2[key]
			elif key not in dict2:
				k -= value
		if k >= 0:
			return True
		return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		else:
			d1 = {x: 0 for x in str1}
			d2 = {x: 0 for x in str2}
			z = 0
			for i in str1:
				d1[i] += 1
			for i in str2:
				d2[i] += 1
			a = set(str1)
			b = set(str2)
			c = a.union(b)
			for i in c:
				if i in d1.keys() and i in d2.keys():
					z += abs(d1[i] - d2[i])
					continue
				if i in d1.keys() and i not in d2.keys():
					z += d1[i]
					continue
				if i in d2.keys() and i not in d1.keys():
					z += d2[i]
			if z % 2 != 0:
				return False
			if z // 2 <= k:
				return True
			return False


from collections import defaultdict

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return 0
		d1 = defaultdict(int)
		d2 = defaultdict(int)
		for i in str1:
			d1[i] += 1
		for i in str2:
			d2[i] += 1
		for i in d1:
			if d1[i] > d2[i]:
				k -= d1[i] - d2[i]
		if k >= 0:
			return 1
		return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		count = [0] * 26
		for i in range(len(str1)):
			count[ord(str1[i]) - ord('a')] += 1
			count[ord(str2[i]) - ord('a')] -= 1
		diff = 0
		for i in range(26):
			if count[i] > 0:
				diff += count[i]
			if diff > k:
				return False
		return True


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return 0
		s1 = Counter(str1)
		s2 = Counter(str2)
		for i in s1:
			if i not in s2:
				k -= s1[i]
			elif s1[i] > s2[i]:
				k -= s1[i] - s2[i]
		if k >= 0:
			return 1
		else:
			return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		s1 = list(str1)
		s2 = list(str2)
		if len(s1) != len(s2):
			return 0
		d1 = {}
		d2 = {}
		for i in s1:
			if i not in d1:
				d1[i] = 1
			else:
				d1[i] += 1
		for i in s2:
			if i not in d2:
				d2[i] = 1
			else:
				d2[i] += 1
		for i in d1:
			if i in d2:
				if d1[i] > d2[i]:
					d1[i] -= d2[i]
				else:
					d1[i] = 0
		s = 0
		for i in d1:
			s += d1[i]
		return s <= k


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		from collections import defaultdict
		d1 = defaultdict(int)
		d2 = defaultdict(int)
		for i in str1:
			d1[i] += 1
		for i in str2:
			d2[i] += 1
		for i in d1:
			if i in d2 and d1[i] > d2[i]:
				k -= d1[i] - d2[i]
			elif i not in d2:
				k -= d1[i]
		return False if k < 0 else True


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		freq_1 = {}
		for char in str1:
			freq_1[char] = freq_1.get(char, 0) + 1
		diff = 0
		for char in str2:
			if freq_1.get(char, 0) > 0:
				freq_1[char] -= 1
			else:
				diff += 1
		return 1 if diff <= k else 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		dic = {}
		if len(str1) != len(str2):
			return 0
		for i in str1:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
		count = 0
		for j in str2:
			if j in dic:
				dic[j] -= 1
				if dic[j] == 0:
					dic.pop(j)
			else:
				count += 1
			if count > k:
				return False
		return True


class Solution:

	def areKAnagrams(self, a, b, k):
		if len(a) != len(b):
			return False
		(d1, d2) = ({}, {})
		for c in a:
			d1[c] = d1.get(c, 0) + 1
		for c in b:
			d2[c] = d2.get(c, 0) + 1
		keys = d2.keys()
		for c in keys:
			if c in d1:
				d1[c] = d1[c] - d2[c] if d1[c] - d2[c] > 0 else 0
		return False if sum(d1.values()) > k else True


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		count1 = [0] * 26
		count2 = [0] * 26
		for i in range(len(str1)):
			count1[ord(str1[i]) - ord('a')] += 1
			count2[ord(str2[i]) - ord('a')] += 1
		count = 0
		for i in range(26):
			if count1[i] > count2[i]:
				count += abs(count1[i] - count2[i])
		return count <= k


class Solution:

	def areKAnagrams(self, str1, str2, k):
		dic = {}
		for i in str1:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
		dic2 = {}
		for i in str2:
			if i in dic2:
				dic2[i] += 1
			else:
				dic2[i] = 1
			if i in dic:
				dic[i] -= 1
				if dic[i] == 0:
					dic2.pop(i)
					dic.pop(i)
		(c, c2) = (0, 0)
		for i in dic.keys():
			c += dic[i]
		for i in dic2.keys():
			c2 += dic2[i]
		if len(str1) == len(str2) and min(c, c2) <= k:
			return 1
		return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		dic = {}
		if len(str1) != len(str2):
			return 0
		for i in str1:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
		c = 0
		for i in str2:
			if i in dic:
				if dic[i] != 0:
					dic[i] -= 1
				else:
					c += 1
			else:
				c += 1
		if c > k:
			return 0
		return 1


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) == len(str2):
			l1 = []
			d1 = {}
			d2 = {}
			for i in str1:
				if i not in d1:
					d1[i] = 1
				else:
					d1[i] += 1
			for i in str2:
				if i not in d2:
					d2[i] = 1
				else:
					d2[i] += 1
			for i in d1:
				try:
					if d2[i] != d1[i]:
						if d1[i] > d2[i]:
							k1 = [i] * abs(d2[i] - d1[i])
							l1 += k1
				except:
					k1 = [i] * d1[i]
					l1 += k1
			if len(l1) <= k:
				return True
		return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) == len(str2):
			map = {}
			for (x, y) in zip(str1, str2):
				if map.get(x) is None:
					map[x] = 1
				else:
					map[x] += 1
				if map.get(y) is None:
					map[y] = -1
				else:
					map[y] -= 1
			sum = 0
			for x in map.values():
				sum += abs(x)
			if sum // 2 <= k:
				return True
			else:
				return False
		else:
			return False


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return 0
		ht1 = Counter(str1)
		ht2 = Counter(str2)
		ht = ht2 - ht1
		sum_val = sum([val for val in ht.values()])
		if sum_val <= k:
			return 1
		return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		maxchar = 26
		if len(str1) != len(str2):
			return 0
		k1 = [0] * maxchar
		k2 = [0] * maxchar
		count = 0
		for i in range(len(str1)):
			k1[ord(str1[i]) - ord('a')] += 1
		for i in range(len(str1)):
			k2[ord(str2[i]) - ord('a')] += 1
		for i in range(maxchar):
			if k1[i] > k2[i]:
				count += abs(k1[i] - k2[i])
		if count <= k:
			return 1
		else:
			return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		freq1 = [0] * 26
		freq2 = [0] * 26
		m = 0
		if len(str1) != len(str2):
			return False
		for i in str1:
			freq1[ord(i) - ord('a')] = freq1[ord(i) - ord('a')] + 1
		for i in str2:
			freq2[ord(i) - ord('a')] = freq2[ord(i) - ord('a')] + 1
		for i in range(0, 26):
			if freq1[i] != freq2[i]:
				m = m + abs(freq1[i] - freq2[i])
		if m / 2 <= k:
			return True
		return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		dict1 = {}
		for i in str1:
			dict1[i] = dict1.get(i, 0) + 1
		for i in str2:
			if i in dict1:
				if dict1[i] > 0:
					dict1[i] -= 1
		sum = 0
		for i in dict1:
			sum += dict1[i]
		if sum > k:
			return False
		return True


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		st = {}
		for i in range(len(str1)):
			st[str1[i]] = 1 + st.get(str1[i], 0)
		for i in range(len(str2)):
			st[str2[i]] = st.get(str2[i], 0) - 1
		sum_ = 0
		for i in st.values():
			if i > 0:
				sum_ += i
		return 1 if sum_ <= k else 0


from collections import *

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		d1 = defaultdict(int)
		for i in str1:
			d1[i] += 1
		count = 0
		for j in str2:
			if j in d1 and d1[j] > 0:
				d1[j] = d1[j] - 1
		for i in d1:
			count += d1[i]
		if count <= k:
			return True
		return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		hashMap1 = {}
		hashMap2 = {}
		for i in range(len(str1)):
			hashMap1[str1[i]] = hashMap1.get(str1[i], 0) + 1
			hashMap2[str2[i]] = hashMap2.get(str2[i], 0) + 1
		count = 0
		for key in hashMap1.keys():
			if hashMap1[key] > hashMap2.get(key, 0):
				count += hashMap1[key] - hashMap2.get(key, 0)
		return True if count <= k else False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		s = ''
		if len(str1) != len(str2):
			return 0
		if len(str1) == k:
			return 1
		else:
			for i in str1:
				if i in str2:
					x = str2.index(i)
					str2 = str2[:x] + str2[x + 1:]
				else:
					s = s + i
			if len(s) > k:
				return 0
		return 1


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return 0
		dic1 = {}
		dic2 = {}
		for i in range(26):
			dic1[ord('a') + i] = 0
			dic2[ord('a') + i] = 0
		for i in range(len(str1)):
			dic1[ord(str1[i])] += 1
			dic2[ord(str2[i])] += 1
		res = 0
		for i in range(len(str1)):
			ord_val = ord(str1[i])
			if dic1[ord_val] > dic2[ord_val]:
				res += abs(dic1[ord_val] - dic2[ord_val])
				dic1[ord_val] = 0
		if res <= k:
			return 1
		return 0


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		(c1, c2) = (Counter(str1), Counter(str2))
		if len(str1) != len(str2):
			return 0
		cmn = []
		for (elem, freq) in c1.items():
			if elem in c2:
				cmn.append(elem)
		for each in cmn:
			if c1[each] and c2[each]:
				if c1[each] == c2[each]:
					c1.pop(each)
					c2.pop(each)
				elif c1[each] > c2[each]:
					c1[each] = c1[each] - c2[each]
					c2.pop(each)
				else:
					c2[each] = c2[each] - c1[each]
					c1.pop(each)
		(x, y) = (0, 0)
		for (elem, freq) in c1.items():
			x += freq
		for (elem, freq) in c2.items():
			y += freq
		if x == y and x <= k and (y <= k):
			return 1
		else:
			return 0


class Solution:

	def areKAnagrams(self, p, j, k):
		if len(p) != len(j):
			return False
		q = {}
		r = {}
		for i in p:
			if i in q:
				q[i] += 1
			else:
				q[i] = 1
		for i in j:
			if i in r:
				r[i] += 1
			else:
				r[i] = 1
		op = 0
		for i in q:
			if i not in r:
				op += q[i]
			elif q[i] > r[i]:
				op += q[i] - r[i]
		if op <= k:
			return True
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		m = {}
		n = {}
		for i in str1:
			if i in m:
				m[i] += 1
			else:
				m[i] = 1
		for i in str2:
			if i in n:
				n[i] += 1
			else:
				n[i] = 1
		operations = 0
		for i in m.keys():
			if i not in n:
				operations += m[i]
			elif m[i] > n[i]:
				operations += m[i] - n[i]
		if operations <= k:
			return True
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		str1_length = len(str1)
		str2_length = len(str2)
		a = [0] * 26
		count = 0
		if str1_length == str2_length:
			for i in range(0, str1_length):
				a[ord(str1[i]) - ord('a')] += 1
			for i in range(0, str2_length):
				if a[ord(str2[i]) - ord('a')] > 0:
					a[ord(str2[i]) - ord('a')] -= 1
					count += 1
			if str1_length - count <= k:
				return 1
		else:
			return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) == len(str2):
			n = len(str1)
			c1 = [0] * 26
			c2 = [0] * 26
			for i in range(n):
				c1[ord(str1[i]) - 97] += 1
				c2[ord(str2[i]) - 97] += 1
			c = 0
			for i in range(26):
				if c2[i] > c1[i]:
					c += abs(c2[i] - c1[i])
			return c <= k
		return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		freq1 = {}
		for ch in str1:
			if ch in freq1:
				freq1[ch] += 1
			else:
				freq1[ch] = 1
		freq2 = {}
		for ch in str2:
			if ch in freq2:
				freq2[ch] += 1
			else:
				freq2[ch] = 1
		operations = 0
		for x in freq1.keys():
			if x not in freq2:
				operations += freq1[x]
			elif freq1[x] > freq2[x]:
				operations += freq1[x] - freq2[x]
		if operations <= k:
			return True
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		n1 = len(str1)
		n2 = len(str2)
		if n1 != n2:
			return 0
		d1 = {}
		d2 = {}
		for i in range(n1):
			d1[str1[i]] = d1.get(str1[i], 0) + 1
			d2[str2[i]] = d2.get(str2[i], 0) + 1
		cnt = 0
		for elt in d1:
			f = d2.get(elt, 0)
			if f > d1[elt]:
				f = d1[elt]
			cnt = cnt + d1[elt] - f
		if cnt <= k:
			return 1


class Solution:

	def areKAnagrams(self, str1, str2, k):
		(n, m) = (len(str1), len(str2))
		if n != m:
			return 0
		(map, cnt) = ({}, 0)
		for i in range(n):
			map[str1[i]] = map.get(str1[i], 0) + 1
		for i in range(n):
			if map.get(str2[i], 0):
				map[str2[i]] = map.get(str2[i], 0) - 1
			else:
				cnt += 1
		if cnt <= k:
			return 1
		return 0


from collections import defaultdict

class Solution:

	def areKAnagrams(self, str1, str2, k):
		l1 = len(str1)
		l2 = len(str2)
		d1 = defaultdict(int)
		d2 = defaultdict(int)
		diff1 = 0
		diff2 = 0
		if l1 == l2:
			for i in range(l1):
				d1[str1[i]] += 1
			for i in range(l2):
				d2[str2[i]] += 1
			s1 = set(list(str1))
			s2 = set(list(str2))
			ls = list(s1.intersection(s2))
			ld1 = list(s1.difference(s2))
			for i in ld1:
				diff1 += d1[i]
			ld2 = list(s2.difference(s1))
			for i in ld2:
				diff2 += d2[i]
			for i in ls:
				if d1[i] > d2[i]:
					diff1 += d1[i] - d2[i]
				else:
					diff2 += d2[i] - d1[i]
			if diff1 <= k or diff2 <= k:
				return True
			else:
				return False
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		d = {}
		for i in str1:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		p = 0
		for i in str2:
			if i in d:
				if d[i] == 1:
					del d[i]
				else:
					d[i] -= 1
				p += 1
		if p + k < len(str1):
			return False
		return True


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		hashmap = dict()
		for i in range(len(str1)):
			hashmap[str1[i]] = hashmap.get(str1[i], 0) + 1
			hashmap[str2[i]] = hashmap.get(str2[i], 0) - 1
		ans = [abs(value) for value in hashmap.values() if value != 0]
		return sum(ans) // 2 <= k


class Solution:

	def areKAnagrams(self, str1, str2, k):
		d = dict()
		if len(str1) != len(str2):
			return False
		for i in str1:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
		for i in str2:
			if i in d:
				if d[i] > 0:
					d[i] -= 1
		sum = 0
		for i in d:
			sum += d[i]
		if sum <= k:
			return True
		return False


from collections import Counter

class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) == len(str2):
			c = Counter(str1)
			for j in str2:
				if j in c and c[j] > 0:
					c[j] -= 1
			cnt = sum(list(c.values()))
			if cnt > k:
				return 0
			return 1
		return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		i = 0
		if len(str1) != len(str2):
			return 0
		while i < len(str1):
			if str1[i] in str2:
				temp = str1[i]
				str1 = str1.replace(temp, '', 1)
				str2 = str2.replace(temp, '', 1)
				continue
			i += 1
		if len(str1) <= k:
			return 1
		return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return 0
		dicty = {}
		for i in str1:
			if i in dicty:
				dicty[i] += 1
			else:
				dicty[i] = 1
		for i in str2:
			if i in dicty:
				if dicty[i] >= 0:
					dicty[i] -= 1
		count = 0
		for i in dicty:
			if dicty[i] > 0:
				count += dicty[i]
		if k >= count:
			return 1
		else:
			return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		dict = {}
		for i in str1:
			if i in dict:
				dict[i] += 1
			else:
				dict[i] = 1
		for j in str2:
			if j in dict and dict[j] > 0:
				dict[j] -= 1
		total = 0
		for l in dict:
			total += dict[l]
		if total <= k:
			return True
		else:
			return False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		b = {}
		for i in str1:
			if i not in b:
				b[i] = 0
			b[i] += 1
		total = len(str2)
		for i in str2:
			if i in b and b[i] > 0:
				b[i] -= 1
				total -= 1
		return total <= k


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		map = {}
		for i in str1:
			map[i] = map.get(i, 0) + 1
		count = 0
		for j in str2:
			if j in map and map[j] > 0:
				map[j] -= 1
			else:
				count += 1
			if count > k:
				return False
		return True


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		from collections import Counter
		c1 = Counter(str1)
		c2 = Counter(str2)
		if sum((c2 - c1).values()) <= k:
			return True
		else:
			False


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		d = {}
		for s in str2:
			if s not in d.keys():
				d[s] = 1
			else:
				d[s] += 1
		unmatch_count = 0
		for p in str1:
			if p not in d.keys() or d[p] == 0:
				unmatch_count += 1
			else:
				d[p] -= 1
		if unmatch_count > k:
			return False
		else:
			return True


from collections import defaultdict

class Solution:

	def areKAnagrams(self, str1, str2, k):
		d = defaultdict(lambda : 0)
		if len(str1) != len(str2):
			return 0
		else:
			cnt = 0
			for i in range(len(str1)):
				d[str1[i]] += 1
			for i in range(len(str2)):
				if str2[i] not in d.keys() or d[str2[i]] == 0:
					cnt += 1
				else:
					d[str2[i]] -= 1
			if cnt <= k:
				return 1
			else:
				return 0


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		l = len(str1)
		freq1 = [0] * 26
		freq2 = [0] * 26
		for i in range(l):
			freq1[ord(str1[i]) - ord('a')] += 1
		for i in range(l):
			freq2[ord(str2[i]) - ord('a')] += 1
		total = 0
		for i in range(26):
			if freq1[i] > freq2[i]:
				total = total + abs(freq1[i] - freq2[i])
		return total <= k


class Solution:

	def areKAnagrams(self, str1, str2, k):
		if len(str1) != len(str2):
			return False
		dictt = {}
		for i in range(len(str1)):
			if str1[i] in dictt:
				dictt[str1[i]] += 1
			else:
				dictt[str1[i]] = 1
		count = 0
		for i in range(len(str2)):
			if str2[i] in dictt and dictt[str2[i]] > 0:
				dictt[str2[i]] = dictt[str2[i]] - 1
			else:
				count = count + 1
		return count <= k


class Solution:

	def areKAnagrams(self, str1, str2, k):
		n1 = len(str1)
		n2 = len(str2)
		count = 0
		if n1 != n2:
			return False
		for i in range(n1):
			if str1[i] in str2:
				count += 1
				str2 = str2.replace(str1[i], '', 1)
		if n1 - count <= k:
			return True
		return False