/*
source == "facebook", target == "fee": return 2
source == "facebook", target == "BOO": return 1
source == "facebook", target == "coffee kebab": return 3
*/
function findMatchCount(source , target){
const sourceMap = buildMap(source.toLowerCase())
const targetMap = buildMap(target.toLowerCase())
let count = 0
for(const [key, val] of targetMap){
if(!sourceMap.has(key)) return 0
let devided = Math.ceil(val / sourceMap.get(key))
count = Math.max(count, devided)
}
return count
}
function buildMap(str, map = new Map()){
for(let c of str){
if(c === ' ') continue
map.set(c, (map.get(c) || 0) + 1)
}
return map
}
let source = "facebook", target = "fee" //: return 2
console.log(findMatchCount(source, target))
target = "BOO" //return 1
console.log(findMatchCount(source, target))
target = "coffee kebab" // return 3
console.log(findMatchCount(source, target))Comments (1)


