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 arraynot enough tests: please use the python or java translation as reference.
Add an example in Swift to the description.
Many thanks for taking the time to translate my Kata. The C code looks perfectly fine to me and I was about to approve it but unfortunately the CW system said that there were merge conflicts in the Kata description (because I approved your Swift translation first). For this reason, I have forked your translation to resolve the merge conflicts (and add a bit of C-specific information in the Description as well) and approved the fork instead, hope you don't mind :)
I created the function in Swift and when i submit my code it passes all test except for "Multiply non-negative bytes with product less than 256". The exact error is 'XCTAssertEqual failed: ("Ã") is not equal to ("ÿ") -'. I saw the other question about code not passing this test so i changed it so my output was returned as a ISO_8859_1
return String(bytes: out_data, encoding: .isoLatin1 )
string but i am still getting exact same error. Any advice about where i have gone wrong would be much appriciated.