# Tag Info

6

Disclaimer. This ia not a proper review, but an extended comment. Nice work with understanding the core of the problem. You just need to go one extra mile to come up with the closed form solution. If you rewrite the loop as Choosy = 1 sub = 0 for i in range(questions + 1): sub += triangular * Choosy triangular += zero + 1 Choosy = Choosy * (...

6

Normally I do a design review first, then review the code itself. This time I’m going to switch it around. Code review Before I get into review this code, I just have to say that the sample solution code given is… ghastly. Seriously, if someone worked at a software company I owned, and they submitted that kind of code, I’d not only fire them, I’d have them ...

3

In your memoization you cannot distinguish between target sums that have not been evaluated, and ones that you have evaluated but have no solution. This results in re-running these unsuccessful possibilities. You should add some way to tell these two cases apart: Either use an empty vector to indicate that there is no viable sum, or use a class that stores ...

2

When I execute your solution, I get a result that says that the submission is faster than ~5% of submissions and uses less memory than ~5% of submissions. The following solution ran faster than ~94% of submissions and used less memory than ~92% of submissions. var firstUniqChar = function(s) { const characterCounts = new Array(26).fill(0); for (let index ...

2

Reduce the numbers You compute potentially huge numbers, which is slow. And you forgot about the modulo $10^9+7$, you're not doing that anywhere. If you do it at each step, then you work only with small numbers, which is much faster. For example, instead of 2 ** questions use pow(2, questions, 10**9 + 7). Keeping your numbers modulo $10^9+7$ makes your ...

2

I don't fully understand the solution, but here are some improvements for the code: You are computing related quantities twice: In: if questions != 0: total = total * 2 ** questions + count * 2 ** (questions - 1) you are computing 2 ** questions and 2 ** (questions - 1). You can just compute a = 2 ** (questions - 1), and then compute 2 ** questions as 2 ...

1

Make the logic more obviously correct This piece of code made me doubt if the logic is correct: for(let entry of myMap){ if(entry == 1){ return entry } } My first doubt was the iteration order of Map entries. In most languages that I know, the iteration order of map data structures is undefined. I had to lookup in the docs to ...

1

Making memoziation super-easy to read The common pattern of memoization looks something like this: const fun = function(param) { if (memo[param] !== undefined) return memo[param]; // compute the actual answer, for "param" let answer = ... memo[param] = answer; return answer; }; That is, the first thing that happens in the function is ...

Only top voted, non community-wiki answers of a minimum length are eligible