Skip to main content
8 votes

LeetCode 2. Add Two Numbers

Within the confines of Leetcode's requirements, this is about as straightforward a solution as can be hoped for. A few style suggestions have been pointed out by toolic. The following code can be ...
Chris's user avatar
  • 6,844
6 votes
Accepted

LeetCode 2. Add Two Numbers

Naming The PEP 8 style guide recommends snake_case for function and variable names. I realize the LeetCode site requires you to give the primary function those names, but you would otherwise name the ...
toolic's user avatar
  • 16.8k
4 votes

Memorise array and print number of occurrences

You do not need to store all numbers in arrays You can immediately use the values from the input. So the first fallacy is: ...
Joop Eggen's user avatar
  • 4,806
3 votes

Hackerearth: Counting numbers in an array that are divisible by any 2 numbers

Always assume that coding challenge websites will give you worst case scenarios to test your code. They won't test your code with small arrays of small numbers. They'll give you large arrays with huge ...
Chris's user avatar
  • 6,844
2 votes

LeetCode 22. Generate Parentheses (C++)

By default, std::stack uses std::deque as it's underlying container. However, this is just the default, and any container which ...
Chris's user avatar
  • 6,844
1 vote

Advent of Code 2023 day 1: Trebuchet (Part 1)

There is an opportunity in modern C++ to offload the processing of each line using std::views::istream. ...
Chris's user avatar
  • 6,844
1 vote

Hackerearth: Counting numbers in an array that are divisible by any 2 numbers

Portability I realize this question was posted many years ago when Python version 2.x was prevalent, but now that it is deprecated, consider porting to 3.x. To do so, it is necessary to add ...
toolic's user avatar
  • 16.8k

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