No Idea! - Python Set Problem Solution

No Idea! - Python Set Problem Solution

Instructor-svgAl-Mamun Sarkar
Mar 24 , 2020

No Idea! - Python Set Problem Solution. This is a solution to a HackerRank python sets problem. Click here to see the problem on HackerRank. 

Code:


def happiness(input_array, A, B):
	happiness_score = 0
	for i in input_array:
		if i in A:
			happiness_score += 1
		if i in B:
			happiness_score -= 1
	return happiness_score


def main():
	n, m = input().split()
	input_array = list( map( int, input().split() ) )
	A = set( map( int, input().split() ) )
	B = set( map( int, input().split() ) )
	print( happiness( input_array, A, B ) )


if __name__ == '__main__':
	main()

  

 

Test Input:

3 2
1 5 3
3 1
5 7

Test Output:

1
  • Share On:
  • fb
  • twitter
  • pinterest
  • instagram