sudopower

lc_bwc_156_q1

LC: BWC 156: Q1: Most frequent vowel and consonant

Link to problem

Solution 1

func maxFreqSum(s string) int {
    freq := make(map[string]uint8,26)
    n:= struct{}{}
    vowels := map[string]struct{}{"a":n,"e":n,"i":n,"o":n,"u":n}    
    
    var maxVcnt, maxCcnt uint8
    for _,char := range s {
        freq[string(char)]+=1
    }

    for char,cnt := range freq{
        if _,exist:=vowels[char];exist{
            if cnt>maxVcnt{
                maxVcnt=cnt                
            }
            continue
        }

        if cnt>maxCcnt{
            maxCcnt=cnt            
        }
    }    

    return int(maxVcnt+maxCcnt)
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blogs