Methods to do 2D memoization - discuss alternatives?

I was doing the "Explore" module and came across the Pascal's triangle problem. One technique is to do 2D memoization technique and this tripped me a little and I want to ask what's the general best way to implement 2D memoization?

Say, traditional way is 2D array - but this is limited to compile time size. Sure, we could do dynamic 2D array allocation, but as I had personally done this in say setting up minesweeper grid - it is not fun and easy to do - especially on a whiteboard.

Hashmap came to mind, easiest to deal with - however the 2D integer aspect of indexing is a little tricky.

I ended up converting the 2D integers into a string and use it to index the map.

idx = to_string(i) + "_" + to_string(j);
mymap[idx] = result;

Is there a more "beaufiful" way (faster, easier, better) to handle such cases?

Comments (1)