Find one element from each of two arrays whose sum is equal to value present in third array

  • 0

    Given 3 integer arrays: A=[1,3,-1], B=[2, 4, 0, 5], and C=[3, 6, 7], find all pairs of elements (one from A, one from B, we have to use elements in
    both arrays), such that the sum is from C

    My Solution:

       // takes O(n^3)
    for( i= 0; i< A.length-1; i++)
    	for( j= 0; j<B.length-1; j++)
            for(int p= 0; p< c.length-1 ; p++ )
        {	if((A[i]+B[j])= c[p])
    		System.out.println(“Pairs: “+ A[i]+” ”+B[K]);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.