why my code is wrong? i'm just curious where the logic went wrong it failed at test case:6 Your text to link here... Please help me ASAP
why my code is wrong? i'm just curious where the logic went wrong it failed at test case:6 Your text to link here... Please help me ASAP
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | jiangly | 3670 |
| 3 | Kevin114514 | 3657 |
| 4 | maroonrk | 3355 |
| 5 | Um_nik | 3353 |
| 6 | squareOf105 | 3346 |
| 7 | tourist | 3343 |
| 8 | strapple | 3324 |
| 9 | heuristica | 3322 |
| 10 | jiangbowen | 3291 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 158 |
| 2 | nik_exists | 150 |
| 2 | maspy | 150 |
| 4 | AmShZ | 143 |
| 5 | Um_nik | 141 |
| 6 | Errichto | 139 |
| 7 | adamant | 137 |
| 8 | BledDest | 133 |
| 8 | maroonrk | 133 |
| 10 | qwexd | 130 |
| Name |
|---|



You fail to consider the case where there's more than one of the same character. For example, in the test case "www", your program says "chat with her", but the answer should be "ignore him". After count-=1, you should do "if (count>0) count=1;"
1) When i is equal to j, n (the j-th character) will always be equal to
c[i]. Try starting yourforat i = j + 1.2) You need to break out of the
forloop whenn == c[i]is true, in order to not count repeating characters multiple times.3) Because you are already subtracting
c.Lengthfromcount(character by character when doingcount = count-1),countafter the for loop is exactly the number of distinct characters, but with a minus sign. There are two ways to fix the calculation of k, the number of distinct characters: Either delete thecount = count-1line (and keepk = c.Length - count, becausecountwould then represent the number of repeated letters) or usek = -count.I submitted your solution with the proposed changes here.
Thanks for the help I understood it crisp and clear Can you add me as a friend?