This problems present and looks hard but this not if have solved all prior sets problems this pretty easy here we have given two sets A and B and an array size of n , array can contain duplicate elements
and you know sets remove duplicate and we have total happiness initialize as 0 and we look inside sets if array elements are there or not and its in A then we add up 1 to total_happines and if it in B we add up -1 to total_happines and in last we just return or print the total_happines nothing special.
Problem:https://www.hackerrank.com/challenges/no-idea/problem?isFullScreen=true
Code:
# Enter your code here. Read input from STDIN. Print output to STDOUT
n , m = map(int, input().split())
arr = list(map(int, input().split()[:n]))
total_happiness = 0
A = set(map(int, input().split()[:m]))
B = set(map(int, input().split()[:m]))
'''
for i in arr:
if i in A:
total_happiness +=1
if i in B:
total_happiness -= 1
'''
'''We can use both and both works fine here is just that we do in less line but logic same and we re assign it 0nothing speccial we can also use sum() but cause we have to initialize total_happiness that why this: '''
for i in arr:
total_happiness += (1 if i in A else -1 if i in B else 0)
print(total_happiness)
'''
This Python script performs a series of operations:
1. It initializes some variables that hold important values.
2. The script processes input data in a function to calculate specific results.
3. It checks conditions, making decisions based on input or calculated values.
4. Finally, it outputs the result or a message to the user.
Overall, this script demonstrates basic operations such as variable handling, control flow, and output generation.
'''
