Calculate your total happiness, which depends on the integers in the given sets
As pointed out in the comments by both MrVajid and AJNeufeld, the previous solution (now deleted because it is actually irrelevant now; see post history) actually did not work.
This is because in reality, the task requires the input array to not be a set, aka it should be allowed to have duplicate entries.

In fact, I had solved that challenge successfully a while ago, using:

n, m = [int(x) for x in input().split()]

array = [int(x) for x in input().split()]
A = {int(x) for x in input().split()}
B = {int(x) for x in input().split()}

happiness = 0

for value in array:
    change = 1 if value in A else -1 if value in B else 0
    happiness += change

print(happiness)


This is using set comprehension ({ }) and passes just fine on HackerRank.

Iteration over the input array as a list is still \$O(n)\$, see here, but containment checks for sets is constant time, \$O(1)\$. Previously, with \$A\$ and \$B\$ being lists, this was also linear as \$O(m)\$, leading to \$O(n*m)\$ aka quadratic time complexity.

Since this task on HackerRank is specifically about set usage, it will judge pedantically about time complexity, with only the approach using sets not running into timeout errors.



Notice that your solution also has an error apart from the set one.
You check for containment in happy_set and decrement happy for a negative result.
However, you first need to check for containment in sad_set first.
Otherwise, you are much sadder than required.