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.
Thanks!
Can someome please explain me why cant I do the assignment like this : ans[i] = str[i]; ?
Thanx
This solution adds extra spaces for new words which are allready uppercase, as far as I understood this was not the task. Also there is no allocation for on empty string which still needs termination (as far as I know strlen does not count the null termination).
I think this produces a wrong output for "abc D" which is "abc D" and I think if called with "" is undefined behaivior or system dependend
nah, I think it's to give extra space in case of memory overflow
That really depends on the length of the strings you are going to be processing and your hardware, but now a days memory is cheap. The context of this problem is comments, there is usually a character limit, let's say you have a 1000 character limit, Then at best you'll be allocating 1kB for the comment and another 1kB for the answer, thats 2kB total. On the other hand if you count the number of non-vowel characters you are going to check the string twice no matter what and in the worst case scenario you are going to be allocating 2kB either way if the comment doesn't contain any vowel. It's a trade off, you are saving a little bit of memory for processing power.
Yes, it's a trade off.
In your solution, which does not waste memory, you check the whole string twice.
Another solution would be to first create the wasteful buffer, write the solution into it, now determine the actual size.
Create a new buffer, copy the string from the wasteful buffer, free the wasteful buffer, return the new memory optimized buffer.
But hell, we are optimizing something really tiny and even if the string was quite large, then this third solution would be problematic, because temporarily you need almost twice the memory.
Did you forget to flag you reply as spoiler? as it appeared in my dashboard
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