Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
supcio
awesome
I don't think I have ever done anything even remotely so hard and exhasting as this. Seriously, it was a nightmare. It took me many hours over few days, not letting me think about pretty mych anything else. Now I feel strange when it's finally done. Amazing experience. Thank you!
See comments in my TypeScript solution for explanation and how my first solution was needlessly complex.
See comments to my TypeScript solution for explanation, and how my previus solution was needlessly complicated.
See comments to my TypeScript solution for an explanation on why it works and how much worse was my first solution.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
See my other solution for simpler code and explanation in comments.
For a much shorter solution but wuth O(n) space complexity, see:
https://www.codewars.com/kata/reviews/5656bd079c771d9d4e00001b/groups/62b0d07d042101000199149f
For O(1) space solution that doesn't allocate potentially huge memory, see:
https://www.codewars.com/kata/reviews/5656bd079c771d9d4e00001b/groups/62b0ce3181d5d100011f6dd1
This comment is hidden because it contains spoiler information about the solution
(Note: For a more readable version of this code, see my other solution here.)
A lot of other solutions, both small and large and verbose, are brute force solutions that would never work for larger data.
This one is optimal, i.e. it is impossible implement a less complex algorithm.
Test your own and other people solutions with data:
target = 1; array = Array(1000000).fill(0);
This will test the worst-case scenerio of not finding matching numbers anywhere and having to check everything, instead of relying on luch to find the numbers in one of the first iterations.
It is important to keep the time and space complexity in mind and always to trying to find an optimal solution, because most of solutions here will fail most of recruitment tasks, and will fail tests on more restrictive coding platform, e.g. on AlgoExpert - you can use this code to test your solution on platforms that require value instead of index:
const twoNumberSum = (a, t) => twoSum(a, t).map(i => a[i]);
Loading more items...