simontoth,
@simontoth@hachyderm.io avatar

Tuesday common C++ interview problem: O(1) region sum.

Given a 2D grid of integers, provide a method that calculates the sum of a sub-region:

  • int64_t Grid::region_sum(Coord top_left, Coord bottom_right) const;

The methods must operate in O(1). You are allowed preprocessing and O(|grid|) memory.

Solve it yourself: https://compiler-explorer.com/z/nxvqrqfWq
Solution: https://compiler-explorer.com/z/31GMbscxT

  • All
  • Subscribed
  • Moderated
  • Favorites
  • cpp
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines