LeetCode Solutions that I believe to be sub-optimal.
No need for extra space or modifying the array input in-place. Just loop backward.
Bitmasking instead of hash set. Hash set consumes 9 times more space than bitmasking (
There are several redundancies in the solution. Looping through all 26 characters is unnecessary.
You only need to gather the largest
After getting the depth of the tree d, we want to know where the incomplete subtree starts from. For this, we check if the left subtree is "complete". If it is complete, we check for the left subtree of the right subtree. Else, we check for the left subtree of the left subtree.
Though my solution is still
Similar to the official solution, but there's no need to loop from
Instead of checking the pairs of len(nums) - 1
. If nums[i] + nums[j] + nums[k] < target
, we break the while loop and increment the total number of pairs by
One less for loop compared to the official solution.
The code is a lot faster if we set base case to be array size equal to
One less for loop compared to the official solution.
Using the formula for geometric series instead of a while loop significantly improves the speed of counting the number of steps.
Rationale: Think of this as a permutation problem. For any number between