Sunday, 8 July 2018

Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character

both string length should equal for check anagram

public class AnagramDiff {
    public static void main(String args[]) {
        int count = 0;
        String s1 = "spot";
        String s2 = "poat";
        int[] arr = new int[26];
        for(int i=0;i<s1.length();i++) {
            arr[s1.charAt(i)-'a']++;
        }
       
        for(int i=0;i<s2.length();i++) {
            if(--arr[s2.charAt(i)-'a'] <0) {
                count++;
            }
        }
       
        System.out.println("number of manipulation required:"+count);
       
    }
}

No comments:

Post a Comment

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...