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 expression "-i - 1" can be replaced by "~1", which simply flips all bits. It always yields the same value, e.g. if i=-5 [...11111011] then -(-5)-1=4 [...00000100].
If you fiddle the bits some more, you can even save the branch. Since you're effectively flipping all the bits depending on whether the value is negative which is ultimately indicated by the sign bit, you may as well create a bit mask from the sign bit and use it to flip all the bits if necessary, i.e. you can replace something like "(i < 0) ? ~i : i" with the formula "(i >> 31) ^ i".
The last three lines of your code then come down to "Arrays.copyOfRange(TABLE, 0, (i >> 31) ^ i)".
The random test appears to be flawed: for the simple input '(-1a+0)^9' it falsely expected '45a^9' instead of the correct '-a^9'.
I think the while-loop will never terminate, if the input triplets contain a contradiction regarding the order of characters.
A null input should either throw a NullPointerException (discouraged) or should gracefully delegate the null-handling back to the caller by returning null (prefered).
Converting null to an empty string (or any other "empty" object, for that matter) is a bad practice that leads to confusion in more complex code as to where exactly the unexpected "empty" dummy object originated from. An empty string is no different from any other empty object – it has no semantic value but is merely a meaningless stopgap. DON'T PRODUCE EMPTY OBJECTS!
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
The description should be talking about "a shuffled set of numbers" right from the start rather than just "a sequence of numbers". It's confusing to read about shuffling only in the last sentence. There should also be a test case to verify/falsify the handling of shuffled sequences.
The description is unclear about what is a legal input and what is not.
Your loop starts on the third character. You're algorithm will fail on input like " this sentence has a leading space." You're code will also fail on input like "this sentence uses no‑break‑spaces instead of regular spaces."
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Mortonfox's solution is also O(n), although admittedly with large constants.
You could turn the recursive call into a much faster while loop. A smart (JIT) compiler will certainly do so, automatically.
branch free!
branch free (neglecting the loop condition).
branch free (neglecting the loop condition).