Non | Python3 program to find Non - overlapping sum ; Function for calculating Non - overlapping sum of two array ; Insert elements of both arrays ; calculate non - overlapped sum ; Driver code ; size of array ; Function call
from collections import defaultdict NEW_LINE def findSum ( A , B , n ) : NEW_LINE INDENT Hash = defaultdict ( lambda : 0 ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT Hash [ A [ i ] ] += 1 NEW_LINE Hash [ B [ i ] ] += 1 NEW_LINE DEDENT Sum = 0 NEW_LINE for x in Hash : NEW_LINE INDENT if Hash [ x ] == 1 : NEW_LINE INDENT Sum += x NEW_LINE DEDENT DEDENT return Sum NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 5 , 4 , 9 , 2 , 3 ] NEW_LINE B = [ 2 , 8 , 7 , 6 , 3 ] NEW_LINE n = len ( A ) NEW_LINE print ( findSum ( A , B , n ) ) NEW_LINE DEDENT