7 votes
Accepted

Find the best couple of an array in 1.5 seconds

The posted algorithm is a brute force solution, computing the "interestingness" for all pairs of values. In programming competitions in general, a brute-force solution is unlikely to get ...
  • 110k
6 votes

Hangman Game: Revealing guessed letters

The first half of your code is converting the given lst into new_list, with additions for the upper case letters. There are a ...
  • 32.1k
5 votes
Accepted

Hangman Game: Revealing guessed letters

Any non-trivial function ought to have a docstring describing its purpose and any constraints on its arguments. That's also a good place for the unit tests, if we use the ...
  • 60.7k
5 votes

Find the best couple of an array in 1.5 seconds

Implementation I'm missing your includes. You seem to use using namespace std;. Like most namespaces, std is not designed for ...
5 votes
Accepted

Euler Project: Sums of Digit Factorials

First of all, why do you answer multi queries? The problem asks only to find the summation of sg from 1 to 150. The real bottleneck in your solution is this function: ...
4 votes
Accepted

Leet Code 139 (Word Break) using a trie with recursion

Summary: Your code is written clearly, and works correctly as far as I can see. It can be improved at a few points, and string slices can be used for a small performance improvement. In order to make ...
  • 22.6k
3 votes

Leet Code 139 (Word Break) using a trie with recursion

Avoid repeated computations For every prefix that will not lead to a solution, the computation is repeated for all permutations of the words that could produce that prefix. For example given the words ...
  • 110k
2 votes

Cleanly modifying values in hashmap for a k-sum challenge

You have a great implementation-level answer by apilat. I'll address the algorithm: Scan over the input making a hash map of the counts of each integer in the input. Loop over the integers and ...
  • 60.7k
2 votes

Cleanly modifying values in hashmap for a k-sum challenge

Destructuring in for loop Both of your for loops are defined as for n in nums.iter() { .. } This makes ...
  • 263

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