Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 873 Bytes

File metadata and controls

31 lines (24 loc) · 873 Bytes

Given two equal-size strings s and t. In one step you can choose any character of t and replace it with another character.

Return the minimum number of steps to make t an anagram of s.

An Anagram of a string is a string that contains the same characters with a different (or the same) ordering.

Screen Shot 2021-10-26 at 3 32 36 PM

/**
 * @param {string} s
 * @param {string} t
 * @return {number}
 */
var minSteps = function(s, t) {
    let map = {};
    let changes = 0;
    
    for(let letter of s) {
        if(map[letter]) map[letter]++;
        else map[letter] = 1;
    }
    
    for(let letter of t) {
        if(map[letter]) map[letter]--;
        else changes++;
    }
    return changes
};