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.
Bad Practice to catch all Exceptions
"If you use an array to store the number of occurances …"
it sound to me like a histogram, and for that a hash map would be a better data structure.
Your code is correct. However, the test cases are slightly broken so your code won't work.
Just get rid of the first
if
statement and it should be fine.This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Aggree with you. I'm not sure that O(n^2) is a best practice. It looks compact but not optimal.
It would put "a2" since it ignores the usual "" divider that is created at the beginning of the string that now also includes a 1. So divider[0] = "1" when it usually is divder[0]=""
I know this argument went on two years ago but both of these "top 2" solutions use expensive string operations such as .replace(), .lastIndexOf(), and .indexOf() making them O(n^2). If you use an array to store the number of occurances for the 256 ASCII characters and then loop through the string again checking the array for occurances less than 1, you can get a solution that takes O(2n) = O(n).