def calculate_ngram_freqs_solution(ngrams):
    """Calculate the frequency of a subsequent word given a sequence of ngrams

    :param ngrams: [['i', 'will', 'be'], ['will', 'be', 'leaving'], ['be', 'leaving', 'florida']]

    """

    freqs = {}

    for ngram in ngrams:
        # Differentiate successor (= lastWord) ...
        successor = ngram[-1]

        # ... from the ngram sequence
        ngram_seq  = " ".join(ngram[:-1])

        # If a given sequence is not known, initialize 
        # an empty hash map for ngram_seq.
        if ngram_seq not in freqs:
            freqs[ngram_seq] = {}

        # If successor not seen, set th count for 
        # the successor and the given sequence to 0.
        if successor not in freqs[ngram_seq]:
            freqs[ngram_seq][successor] = 0
        
        # Increase frequency of successor given the sequence
        freqs[ngram_seq][successor] += 1

    return freqs