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.
the solution has: Time π(πloglog(π)+π(π/logβ‘π)), Space π(π)
where π is max value from a given array
the illegal values! xD
this has got to be in the top 5 worst kata of all time
agreed
This comment is hidden because it contains spoiler information about the solution
It's not correct, OK? Think about [15, 30, -45] in this kata's description. Such solutions without prime-checking shouldn't pass the kata.
one of the few calculation katas without big numbers and people still copy pasting. smh
Out of curiosity based on how i refactored my solution, why is this more popular of a solution than return (cast) (a+b)? It seems declaring another variable, even a local one, is more work than needs to be done when you can just return the value.
Is there a best practice that says a declared local variable is less prone to bugs or is it just preference as ease of understanding?
what a kata
a
andb
already are of the typebyte
, so casting them will not do anything. However, the addition operator+
returns anint
(as bytes are not necessarily used as numbers, soa + b
implicitly does is(int) a + (int) b
), hence we do need to cast the result.Bit sad given it's not exactly a tough problem. I wouldn't even know how to Google for this, though. I feel like if you knew what terminology to Google you already have a math background.. so wouldn't that make this even easier? This solution is also quite slow.
Considering amount of coders submitted the exactly same solution, this one is clearly copy&paste from internet.
Since Array would start with 0, I guess to make sure the last item in marked[] will corresponed to the largest num (in abs) in the lst[]? This way if that num itself is a prime number, say 101, this prime factor, i.e. itself, will also be included in the calculation.
Why does the length of the marked array have to be m+1?
All is well, except return temp == reverse ? true : false;
You could write just return temp == reverse;
Very clever way of getting the primes and keeping the multiples of primes out. Awesome code. Thank you. Taught me so much reading your code.