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.
This comment is hidden because it contains spoiler information about the solution
This testcase
)(}{][
will lead to anjava.lang.ArrayIndexOutOfBoundsException: 6
on lineif (strInput[i].equals("[") && strInput[i + 1].equals("]")) {
You should click on the down arrow and check for exceptions. And as hobovsky said your program doesnt run correct.
Very interesting read for this question: https://bugs.openjdk.java.net/browse/JDK-8058779.
It says in the description that the empty string is allowed to match.
Nice touch using the AND operator instead of modulo.
I have to disagree recursion is unecessary and clunky. What should be done is repeating a block of code n times, this is achieved by a loop of any kind not recursion. If you unroll above code you have alot of redundancy (null check and creating StringBuilder) and absolutely no benefit.
Using substring that often is very expensive.
For j+=1 just write j++
Your solution to also include the last character if the string has uneven length seems like a big hack and should be avoided. Also substring is waaaay slower than charAt('last index')
Small suggestion:
for(int j=1; j<out.length(); j+=2) temp+=out.charAt(j);
for(int j=0; j<out.length(); j+=2) temp+=out.charAt(j);
This might look friendly, but it is unecessary and might lead to caching problems. You cant have the complete String in memory so you should go once from the beginning till the end. And use modulo to determine even and uneven.
Why use recursion here? First its useless overhead, second it forces unecessary comparison operations and its not easier to read in my oppinion. Recursion is mostly used to solve sub problems not repeat the same block of code a number of times.
For future readers Collections.sort(..,Collections.reverseOrder());
This comment is hidden because it contains spoiler information about the solution