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.
They should not be thought of as Strings ( even if they are - what they really are is just an implementation detail ). Think of them as a three-valued Boolean. They are in a Class of their own.
If you are familiar with Option types, you could also think of them as an Option Boolean, but that introduces unnecessary complexity.
Yes, the author means that these are string
I mean strings in Array
The first argument is the string, the second one is the prefix:
[1, 1, 2, 2, 3]
gives 1+2+3 when the expected answer is 3, since you should not include 1 (it appears more than once) or 2 (it appears more than once) at all.Because you're escaping the backslash like that and you should use a line-break instead:
'\n'
See the sample test:
Some more words: it's probably not useful to spend a lot of time on some katas, if your approach times out. That probably means you are missing some knowledge. A good advice I could give you is: try to practice on very easy katas (8/7 kyus). You will probably be able to solve a good amount of them without too much efforts. Once you solved a kata, you should have a look over the solutions that have been published by other users. By doing this, you will learn a lot of good tips and approaches you had no idea about, and you will see that you will also be able to solve many katas like this one easily. That's what I did, I learnt great part of what I know about programming by doing this.
Your approach is too inefficient to pass this kata. The problem of the method you are using (in both codes you are providing; they are actually equivalent) is that for each item in the list, you need to make a complete loop over the list to get the value you are interested in. If the array has 10 elements, your code will have to make 10 * 10 operations. If the array has 1000 elements, then it will be 1000 * 1000, etc. It's easy to understand that this approach is extremely slow with large arrays. It's hard to give you a concrete answer without giving away the solution. Actually it is possible to solve this kata with only 2 * n operations (with n being the length of the array). Try to think how you could adapt your second code to do it. If you don't manage it, try to make some research with good keywords. In Python, there are some data structures available that almost do all the job for you.
This comment is hidden because it contains spoiler information about the solution
I've copied your solution locally to my computer -- as akar-0 said, in future if you use markdown it's much easier for people to troubleshoot -- your logic is basically fine, your code currently has 2 errors in its implementation.
The first error is a small "programming" error, which is introducing inaccuracies - check your mathematical operations in your code to see if you can find a place where you aren't working correctly with integer values.
The second error is a more important "mathematical" error: you don't need to use large test cases to debug it: try your code on the following string and then calculate the correct answer manually (pen and paper) to see where you are going wrong:
'ABBB' your code gives 8, correct answer is 4. Try to figure out where the discrepancy comes from.
Please use markdown to format your code or it's not readable, it is explained there: https://docs.codewars.com/training/troubleshooting/#post-discourse
Your code has probably the same problem as several persons that have posted questions recently (see comments below). Some operation you are doing is introducing useless inaccuracies, I guess.
You're trying to read the length of None in some part of your code, look for that.