`{"id":"e3116a79-0579-4c7f-93be-0355b2f85243","name":"K Anagrams","description":"1. You are given two strings s1, s2, and a number K.\r\n2. You have to find if two strings are K-anagrams of each other or not.\r\n3. Two strings are called K-anagrams if \r\n -> Both s1 and s2 have the same number of characters.\r\n -> After changing K characters in any string, s1 and s2 become anagram of each other. \r\n\r\nNote -> Both s1 ad s2 consist of lowercase English letters only.","inputFormat":"Two strings s1 and s2\r\nA number K","outputFormat":"true/false","constraints":"1 &lt;= length of string s1 and s2 &lt;= 20,000\r\n1 &lt;= K &lt;= length of strings","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nbool areKAnagrams(string str1, string str2, int k) {\n\t// write your code here\n}\n\nint main(){\n\n\tstring str1;\n\tstring str2;\n\tint k;\n\tcin >> str1 >> str2 >> k;\n\tif(areKAnagrams(str1, str2, k))\n\t cout<<\"true\";\n\telse\n\t cout<<\"false\";\n\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static boolean areKAnagrams(String str1, String str2, int k) {\r\n\t\t// write your code here\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tScanner s = new Scanner(System.in);\r\n\t\tString str1 = s.next();\r\n\t\tString str2 = s.next();\r\n\t\tint k = s.nextInt();\r\n\t\tSystem.out.println(areKAnagrams(str1, str2, k));\r\n\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"fodr \r\ngork\r\n2","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/VyQbl13RGiw?end=83","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"24d63414-c5c4-452a-9455-ac754b34747b","name":"K Anagrams","slug":"k-anagrams","type":1}],"next":{"id":"e3fbec34-c2f9-4993-9690-742fb5f6bcfb","name":"K Anagrams MCQ","type":0,"slug":"k-anagrams-mcq"},"prev":{"id":"a34c4233-beb1-44b8-8749-8be2b9b655ae","name":"Find All Anagrams in a String","type":3,"slug":"find-all-anagrams-in-a-string"}}}`

# K Anagrams

1. You are given two strings s1, s2, and a number K. 2. You have to find if two strings are K-anagrams of each other or not. 3. Two strings are called K-anagrams if -> Both s1 and s2 have the same number of characters. -> After changing K characters in any string, s1 and s2 become anagram of each other. Note -> Both s1 ad s2 consist of lowercase English letters only.

`{"id":"e3116a79-0579-4c7f-93be-0355b2f85243","name":"K Anagrams","description":"1. You are given two strings s1, s2, and a number K.\r\n2. You have to find if two strings are K-anagrams of each other or not.\r\n3. Two strings are called K-anagrams if \r\n -> Both s1 and s2 have the same number of characters.\r\n -> After changing K characters in any string, s1 and s2 become anagram of each other. \r\n\r\nNote -> Both s1 ad s2 consist of lowercase English letters only.","inputFormat":"Two strings s1 and s2\r\nA number K","outputFormat":"true/false","constraints":"1 &lt;= length of string s1 and s2 &lt;= 20,000\r\n1 &lt;= K &lt;= length of strings","sampleCode":{"cpp":{"code":"#include<bits/stdc++.h>\nusing namespace std;\n\nbool areKAnagrams(string str1, string str2, int k) {\n\t// write your code here\n}\n\nint main(){\n\n\tstring str1;\n\tstring str2;\n\tint k;\n\tcin >> str1 >> str2 >> k;\n\tif(areKAnagrams(str1, str2, k))\n\t cout<<\"true\";\n\telse\n\t cout<<\"false\";\n\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main {\r\n\tpublic static boolean areKAnagrams(String str1, String str2, int k) {\r\n\t\t// write your code here\r\n\r\n\t\treturn false;\r\n\t}\r\n\r\n\tpublic static void main(String[] args) {\r\n\r\n\t\tScanner s = new Scanner(System.in);\r\n\t\tString str1 = s.next();\r\n\t\tString str2 = s.next();\r\n\t\tint k = s.nextInt();\r\n\t\tSystem.out.println(areKAnagrams(str1, str2, k));\r\n\r\n\t}\r\n\r\n}\r\n"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"fodr \r\ngork\r\n2","sampleOutput":"true\r\n","questionVideo":"https://www.youtube.com/embed/VyQbl13RGiw?end=83","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"ec6515dc-6811-4c65-912f-0134b65df120","name":"HashMap and Heap For Intermediate","slug":"hashmap-and-heap-for-intermediate-10002","type":0},{"id":"24d63414-c5c4-452a-9455-ac754b34747b","name":"K Anagrams","slug":"k-anagrams","type":1}],"next":{"id":"e3fbec34-c2f9-4993-9690-742fb5f6bcfb","name":"K Anagrams MCQ","type":0,"slug":"k-anagrams-mcq"},"prev":{"id":"a34c4233-beb1-44b8-8749-8be2b9b655ae","name":"Find All Anagrams in a String","type":3,"slug":"find-all-anagrams-in-a-string"}}}`

Editor

# K Anagrams

easy

1. You are given two strings s1, s2, and a number K. 2. You have to find if two strings are K-anagrams of each other or not. 3. Two strings are called K-anagrams if -> Both s1 and s2 have the same number of characters. -> After changing K characters in any string, s1 and s2 become anagram of each other. Note -> Both s1 ad s2 consist of lowercase English letters only.

## Constraints

1 <= length of string s1 and s2 <= 20,000 1 <= K <= length of strings

## Format

### Input

Two strings s1 and s2 A number K

true/false

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}fodr gork 2```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}true ```

Question Video

Discussions

Show Discussion

Related Resources