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.
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
Notif.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Great Kata. I always neglected some concepts in python and this kata made me realise how important they can be. I was stuck doing closures and didn't know how to properly evaluate the function when no more arguments were supplied (essentially my function needed an extra empty () ). Well now I learnt something new the hard way so I won't be forgetting it any time soon.
Without spoiling too much, you can define ranges you want to check using the tests. Start with a small one and then adjust it (lower and upper bound) accordingly.
Eh, yeah. (That's my reaction after solving this). Well, it is a very good kata in the sense that it made me realise that I need to approach things with a more relaxed stance. All in all, humbling and satisfying.
To be honest I don't know either that's why I suggested "trying" withoput pointing out a potential "mistake/useless operation" (I have tried the same thing and it times out compared to the += approach and the two solutions have 8 secs difference between them). I have tried to time both approaches on my local machine and it seems to be minor. Theoretically, I don't think there is a difference because strings are immutable and both approaches should create a new string (as far as I understand). I am looking through the cpython github and if I find something I will update the thread.
Update: I have tried OP's solution as is and it timed out. I have tried the inplace addition and reversing and it worked. I have also tried appending (without inplacing) but at the end and not the beginning then reversing and it also worked. So that seems to be what makes a difference. I am not sure how strings are implemented in python (probably linked lists or something similar) but once I can find the source code for (which I couldn't find, can't find a "_string" file on the github repo) I will update my reply.
Update 2: Check this stack overflow thread : https://stackoverflow.com/questions/37133547/time-complexity-of-string-concatenation-in-python. In the accepted answer's footnote there is a mention of an optimisation to string concatenation. In short when you define two string strA and strB, cpython will avoid creating a new copy when using strA = strA + strB or strA+=strB but not when using strA = strB + strA (prepending). This is in line with what I found so I think it is correct. I hope This helps. Take it with a grain of salt though.
If anyone has a better answer or explanation, then please correct me and/or append to the thread.
Cool, thanks. I have refactored the solution to handle them now.
Python tests don't seem to include negative widths/heights, my solution passes all tests but it never checks for any negative width or height (Per my understanding, a negative height is when the sum of a row or a column is negative and the root operation cannot be performed). If my observation is correct, I think some fixed tests should be added for negative widths/heights.
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Can anyone please approve the python translation ? I am not ready to learn javascript just to remove this kata from my unfinished list hh.
Loading more items...