Non | C # 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
using System ; using System . Collections . Generic ; class GFG { static int findSum ( int [ ] A , int [ ] B , int n ) { Dictionary < int , int > hash = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( hash . ContainsKey ( A [ i ] ) ) { var v = hash [ A [ i ] ] ; hash . Remove ( A [ i ] ) ; hash . Add ( A [ i ] , 1 + v ) ; } else hash . Add ( A [ i ] , 1 ) ; if ( hash . ContainsKey ( B [ i ] ) ) { var v = hash [ B [ i ] ] ; hash . Remove ( B [ i ] ) ; hash . Add ( B [ i ] , 1 + v ) ; } else hash . Add ( B [ i ] , 1 ) ; } int sum = 0 ; foreach ( KeyValuePair < int , int > entry in hash ) { if ( ( entry . Value ) == 1 ) sum += entry . Key ; } return sum ; } public static void Main ( String [ ] args ) { int [ ] A = { 5 , 4 , 9 , 2 , 3 } ; int [ ] B = { 2 , 8 , 7 , 6 , 3 } ; int n = A . Length ; Console . WriteLine ( findSum ( A , B , n ) ) ; } }