function higestFrequency(strings) {
const frecuency = {}
let maxFrecuency = 0
let higestItem = ''
for(let i=0; i < strings.length; i++){ //O(n)
let item = strings[i]
if(frecuency[item] === undefined){
frecuency[item] = 1
}else{
frecuency[item]++
}
// here I am using 2 variables to store the maxFrecuency value and then
// I add the key which is the value I want
if(frecuency[item] > maxFrecuency){
maxFrecuency = frecuency[item]
higestItem = item
}
}
return higestItem
}
console.log(
higestFrequency(['a','b','c','d','e']), // c
higestFrequency(['abc','def','abc','def','abc']), // abc
higestFrequency(['abc','def']), // abc
higestFrequency(['abc','abc','abc','def','def','def','ghi','ghi','ghi','ghi']), // ghi
)
// Time: O(n)
// Space: O(n)