Making Anagrams

  • + 0 comments

    Javascript (Typescript)

    function makingAnagrams(s1: string, s2: string): number {
        let str1: string = s1;
        let str2: string = s2;
    
        for(let i = 0; i < str1.length; i++) {
            let index = str2.indexOf(str1[i]);
            if(index !== -1) {
                str1 = str1.substring(0, i) + str1.substring(i + 1);
                str2 = str2.substring(0, index) + str2.substring(index + 1);
                i--;
            }
        }
        return str1.length + str2.length;
    

    }