Skip to content

Instantly share code, notes, and snippets.

@facekunal
Created July 4, 2020 13:56
Show Gist options
  • Save facekunal/ff8a8fdbd34725cc4cde9719852d1db4 to your computer and use it in GitHub Desktop.
Save facekunal/ff8a8fdbd34725cc4cde9719852d1db4 to your computer and use it in GitHub Desktop.
Swapping pair make sums equal - Naive
boolean isEqualSum(int[] a, int[] b) {
int sumA = Arrays.stream(a).sum();
int sumB = Arrays.stream(b).sum();
for(int i=0;i<a.length;i++){
for(int j=0;j<b.length;j++) {
if (sumA - a[i] + b[j] == sumB - b[j] + a[i]) {
return true;
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment