Skip to content

Instantly share code, notes, and snippets.

@aakashns
Created June 18, 2012 17:41
Show Gist options
  • Save aakashns/2949629 to your computer and use it in GitHub Desktop.
Save aakashns/2949629 to your computer and use it in GitHub Desktop.
Code snippet for 1's and 0's
int diff = 0;
for (int i = 0; i <= n; i++){
if (B[diff + n] == -1) B[diff + n] = i;
else B[diff+ n] = min(B[diff + n], i);
if (C[diff + n] == -1) C[diff + n] = i;
else C[diff + n] = max(C[diff + n], i);
if (i < n && A[i] == 0) diff--;
else diff++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment