Ad
  • Custom User Avatar

    Bad Practice to catch all Exceptions

  • Custom User Avatar

    "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.

  • Default User Avatar

    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.

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    Aggree with you. I'm not sure that O(n^2) is a best practice. It looks compact but not optimal.

  • Default User Avatar

    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]=""

  • Default User Avatar

    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).