Skip to content

Instantly share code, notes, and snippets.

@NedaMani
Created March 5, 2024 14:46
Show Gist options
  • Save NedaMani/336835aec6d23ab150a3018ae149ed6a to your computer and use it in GitHub Desktop.
Save NedaMani/336835aec6d23ab150a3018ae149ed6a to your computer and use it in GitHub Desktop.
rectanglesInsideRectangle
const rectanglesInsideRectangle = (M, N) => {
let rectangles = (M*(M+1)/2) * (N*(N+1)/2);
let min = Math.min(M, N);
let squares = min*(min+1)*(2*min+1)/6;
return rectangles + squares;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment