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 kumited it to Java and included a randomized test case. Thank you!
Agreeing. Both issues take O(n^2) time, and both operations (checking for multiples vs. single occurrence and appending a result string) are doable in O(n) time.
If indexOf(x) and lastIndexOf(x) cached their values (since String is immutable), the result would be O(n), but that's not how String is coded as of Java 8.
The Java compiler optimizes String x += y to the bytecode equivalent of
However, it does not take the optimization a step further to automatically create a single StringBuffer in a loop. That is, it does NOT perform the optimization
...to...
Prior to doing some research, I thought that's what happened under the covers -- but it's clear that I was wrong.
This comment is hidden because it contains spoiler information about the solution
I did not solve this, and my hacky little attempts were pretty minor-league. When I gave up and revealed the solution, I didn't feel so bad that I couldn't solve it. Definitely "advanced language features" here!
Agree completely!
This comment is hidden because it contains spoiler information about the solution
+1 on the "clever" side for using recursion instead of a stack. But isn't a stack more transparent?
Hi, @biswajit86.
For your first situation, I solved this with an algorithm that returns false.
int[] A2 = {21, 22, 23, 24, 11, 12, 13, 14, 1, 2, 3, 4 };
assertEquals(false, calc.isCircleSorted(A2)); // This test case passed and my solution was accepted
Are you sure that this is really a problem?
For your second situation (lists can contain duplicate elements), that's an important thing for programmers to learn when thinking about sorting. If they don't already know that from experience or intution, this Kata is good for reinforcing it.
The requirements say that the last return value is "mocha_missing!" (with exclamation point at the end).
Advice that seasoned developers have given me: Habitually write code that clearly expresses intent, rather than optimizing performance. The compiler and JVM often perform optimizations for you, and profiling tools can be used to expose bottlenecks. But more importantly, premature optimization leads to obscurification of intent, sometimes without any actual performance benefit.