Hi, a little optimization to the solution you have provided: What happens if (sum


#1

Hi, a little optimization to the solution you have provided:
What happens if (sum == target)? Its better to break the while as well as the out for loop in case if we find i, j, k such that A[i]+A[j]+A[k] == target.
No need to search further.
for (i = 0; i <= size-3; i++) {
int exactMatch = 0;
while (j < k) {

        if (A[j] + A[k] < interSum) {
            j++;
        }
        else if (A[j] + A[k] > interSum) {
            k--;
        }
        else { //A[j] + A[k] == interSum
            break;
            exactMatch = 1;
        }
    }
    if (exactMatch)
        break;
}

#2

@Pallavi Gk In your code exactMatch=1; should be before break;