No Idea!

  • + 0 comments

    Since the array might contain duplicate elements, we need to count them. The result is a dictionary with elements as keys and their counts as values:

    counter = Counter(arr)

    Since "For each i integer in the array, if i in A, you add 1 to your happiness" to get total amount of happiness, sum the number of occurrences of A elements in the array:

    happiness = sum(itemgetter(*A)(counter))

    itemgeter is needed to get multiple values from dictionary: https://stackoverflow.com/a/24204498/5106051

    Then do the same for the amount of sadness and combine it with the amount of happiness.