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.
yes, absolutely true! Although I explained this point in a comment before. But then I didn’t know how to use formatting, and it was very difficult to understand the code that I wrote in the comment.
It's a pursuit of brevity.
Probably a bit late, but -48 can be replaced by -'0' for a better understanding
It's compact but I can not agree that this is best practice. I would rather have long readable code than short code that I have to pause on...
This comment is hidden because it contains spoiler information about the solution
This is N Log N time complexity. This task can be completed in N.
Danke you for the clarification
We're playing the code golf (https://en.wikipedia.org/wiki/Code_golf) game, tl;dr write a solution with the minimal number of characters. Yes, in real, production code, you'd use
const
orlet
(var
is still valid, but most modern code useslet
unlessvar
is absolutely necessary, since it has slightly different behavior https://stackoverflow.com/a/11444416/12101554), but this is still valid JavaScript.Use const, let or var!!!
flipao
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Yes, thanks, really very stupid mistake.))))
The number finds itself, as in a mirror
Solution gives wrong results for input
[2,3,1], 4
.You also have O(n), if you want to find solutions with the best result, then there are other sites for this, where this is emphasized. Or you can post 2 solutions. One is short, the other is optimal.
For all arrays of type [0,0,0,1] you have the same result.
I don't think you'll get extra points for fast execution here.
SENSENEL, this is a very good question. Unfortunately, it is a brute force solution that is not optimal. See my solution which is 8 character longer (when removing spaces that were added for readability) but has an optimal O(n) time and O(n) space complexity.
I created a bechmark with a simple case, 1000 elements array, with no matching numbers (to test the worst-case scenerio of searching everything, instead of relying on luck to find the mathing numbers in first iterations). It compares my solution, Niksonman's solution and your solution: jsbench.me/23l4lcraig/1 - try changing the 1000 to million and see what happens.
@SENSENEL, you asked a very good question. In real recruitment tasks, the tests are more complex than here and also check the time and space complexity, so it is important to always keep it in mind. For example try how all of those solutions would pass the tests on AlgoExpert, which has exactly this task as its first task in their Easy list.
Loading more items...