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.
Got the exact same solution! It's a nice feeling haha.
Nice solution ;)
Because the second j starts from i+1 so it will never be equal to i and it skips unnecessary steps.
If your loop has j=0 replace it with j=i+1
I get the same solution lol
This comment is hidden because it contains spoiler information about the solution
If there's no solution, better return an empty array than null.
I think by "different items" means different items of the array, not different values of those items. Hence values can be equal but items (indexes) must be different.
How can O(N^2) be "Best practice"?
The problem statement is "The input will always be valid (numbers will be an array of length 2 or greater, and all of the items will be numbers; target will always be the sum of two different items from that array)."
The input can be repeated numbers, i.e if target is 4 , input can be [2,2,1,3] . The above solution gives (0,1) , but actual ans is(2,3) as target will always be the sum of two different items from that array.