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.
I agree with antong01. This problem is best solved in
O(n)
by not sorting either array, but instead making use of a dictionary. Most of the solutions submitted either use sorting which results inO(n log n)
or searching through an array, which results inO(n^2)
overall. While simple and concise to write, they don't scale as well.While this is a simple solution, it has complexity of
O(n log n)
; For big arrays it could be suboptimal if the first first element ofa
didn't have a match (no early return) or ifb
was an empty arrayUse spoiler flag please.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I didn't think there would be, but that's good to know. Cool!
I did some benchmarking, did each 10,000,000 times several times, can't find any differences outside of the margin of error.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Thank you very much for your help. Now, I can apply that new trick to my future problems. Have a nice day. :)
try this: http://ruby-doc.org/core-2.2.0/String.html#method-i-5B-5D
Could somebody tell me where could I the explaination for this one in the Ruby API? Thanks in advance, and have a nice day.