Divide array into two arrays which does not contain any pair with sum K | C # program for the above approach ; Function to split the given array into two separate arrays satisfying given condition ; Stores resultant arrays ; Traverse the array ; If a [ i ] is smaller than or equal to k / 2 ; Print first array ; Print second array ; Driver Code ; Given K ; Given array ; Given size
using System ; using System . Collections . Generic ; class GFG { static void splitArray ( int [ ] a , int n , int k ) { List < int > first = new List < int > ( ) ; List < int > second = new List < int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= k / 2 ) first . Add ( a [ i ] ) ; else second . Add ( a [ i ] ) ; } for ( int i = 0 ; i < first . Count ; i ++ ) { Console . Write ( first [ i ] + " ▁ " ) ; } Console . WriteLine ( ) ; for ( int i = 0 ; i < second . Count ; i ++ ) { Console . Write ( second [ i ] + " ▁ " ) ; } } public static void Main ( ) { int k = 5 ; int [ ] a = { 0 , 1 , 3 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = a . Length ; splitArray ( a , n , k ) ; } }