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.
O((n1 + n2) * log(n2))
looks better to me thanO(n1 * n2)
, I don't know if I am missing something here. It does depend on the relative lengths ofn1
andn2
though.Technically, his solution is more optimal than the other solutions given. If you use
qsort
(O(n2 log n2)
on the avg. case) onarr2
, andbsort
onarr2
for every element inarr1
((O(n1 log n2)
), then you have a time complexity ofO((n1 + n2) * log(n2))
, while the complexity of the other solutions areO(n1 * n2)
.Every solution I've seen in here is O(n^2), safe to say I don't think there's a better way of doing it (You're calling qsort() once and then bsearch() on every iteration, not sure whether that's O(n^2) or not tbh)
How is this rated as the best solution when the time complexity isnt even optimal?
Initial value of
*lg == -1
is not documented.This shouldn't be a solution, although it's very clever how you gamed the system.
This comment is hidden because it contains spoiler information about the solution
How did this get past the tests?
Thanks!
I redid some little things before publishing, but I could do that myself and you still get the points.
Appreciate your efforts! ( And the chance to read some C. That had been a while. :)
Ok, I changed the custom error messages for the random tests.
Any chance of custom error messages? ( See JavaScript for examples. ) The default messages probably won't give much ( useful ) information to solver.
This should be possible, accordig to the test framework documentation, but it mentions
and I don't really know format strings, given that I don't really know C.
Because "Two strings may have more than one longest common subsequence. When this occurs, return any of them."
I made the changes as requested. However,I'm not sure why we can't just replace those three assertions with just
cr_assert_str_eq(actual,expected);
I think that's incorrect.
length(actual)
should be compared tolength(expected)
, andisSubsequence(string1, actual)
, andstring2
, should betrue
.It looks like you went off the C++ version, which had the subsequence tests wrong also. I fixed that. That one did compare lengths instead of values for
actual
andexpected
.Could you fix this?