How does one approach this problem?

I tried making a nested dictionary storing all pairs. But got stuck after trying to recursively iterate through the dictionary. Is it to be done by DP somehow ? 

Please guide me towards any simillar problems or the theory needed to solve this. I am familiar with only memoization in DP.

Author: AnjaliRai
Login to Answer
Sort By:
Oldest
|
Newest
|
Vote
|
My Answer