Its giving TLE .I am using memoisation but still please tell where the error is?
hello @gaganpreetsachdev1
i think u will be getting run error.
use map in place of array and then it should work.
whats the use of hash map?
using hash map we will allocate memory only for those states that are actually required for computing answer for n. so it save memory
whereas with array we always need to declare array of size n (which may give seg fault becuuse n is upto 10^9)
if(dp.count(n)) return dp[n]; if(n<12) { dp[n]=n; return dp[n]; }
I couldnt understand this part of your code. why dp.count? why <12?
for n<12
answer will be n only thats why we added this as base case.
count function is used to check whether key exist or not in a map.