Data Structures & Algorithms · Revision notes

Arrays & Strings Algorithms

Arrays give O(1) random access through contiguous memory; most interview patterns on arrays and strings reduce O(n^2) brute force to O(n) using two pointers, sliding windows, prefix sums and Kadane-style dynamic programming.

Quick revision

  • Address row-major: base + (i*C + j)*w; column-major: base + (j*R + i)*w
  • Two pointers: sorted + monotone rule, O(n) O(1)
  • Window: add right, shrink left while invalid; negatives break it
  • Prefix: sum(l..r)=P[r+1]-P[l]; seed count[0]=1
  • Kadane: cur=max(x,cur+x); init with a[0]; circular = max(kadane, total-minSub)
Read the full Arrays & Strings Algorithms notes on Doubtclip →