![]() |
VOOZH | about |
Given two strings, the task is to find if they are only less than or equal to k edit distance apart. It means that strings are only k edit distance apart when there are only k mismatches.
Print Yes if there are less than or equal to k mismatches, Else No.
Also, print yes if both strings are already the same.
Examples:
Input : str1 = "geeksforgeeks" str2 = "geeksforgeek" k = 1 Output : Yes Explanation: Only one character is mismatched or to be removed i.e. s at last Input : str1 = "nishant" str2 = "nisha" k = 1 Output : No Explanation: 2 characters need to be removed i.e. n and t Input : str1 = "practice" str2 = "prac" k = 3 Output : No Explanation: 4 characters are mismatched or to be removed i.e. t, i, c, e at last i.e. > k Input : str1 = "Ping" str2 = "Paging" k = 2 Output : Yes Explanation: 2 characters need to be removed or mismatched i.e. a and g in paging
Algorithm:
Implementation:
Yes
Time Complexity : O(n*m), where n and m are length od string1 and string2 respectively.
Auxiliary Space : O(n*m), since we used dp[][] matrix of size n*m.