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.
I've actually tried to do this, but it made the code slower lol.
@Voile I'm late by 4 years, so the opinions of the people here probably change by now. For people who read this in future, time complexity talk is among the most important things in algorithms even for professionals. If your code runs in O(n^2) when it could have run in O(n), you are almost guaranteed to get complains from your clients and a scolding from your superior or colleagues.
Code quality is not black and white, there is no single "right" or "wrong"
(and claiming about that by complaining about "short code" or
"code that uses non-trivial language features" are signs of the speaker being a noob)
I don't think it's about
complaining about "short code"
here, it's the efficiency of the code itself that was in question, which is a quantitative measurement and very objective. Having the time and space complexity of an algorithm in mind while also coding readable, concise code is what really separates the professionals from the average in the programming world.I appreciate you guys commenting and calling out the inefficiencies or else us newer guys would never know.
Most likely to make you laugh.
Why is the exercise worded like a question from stackoverflow?
no,
You may assume the parameter is positive.
excuse me,should we think about that the number must be positive?
yeah, and just multiply that variable +1 with variable +1 instead of calling pow..
Make it generic machine independent code. Good work.
It's seems a general problem on codewars that 'best practise' is interpreted as 'short', regardless of efficiency or readability
IonutArhire - I haven't considered your solution, so I don't know if your issue is ONLY the multiplication, but I did have a thought about how to go about doing the multiplication without access to a 132-bit integer. I would recommend using unsigned, but without giving any spoilers, there are 2 questions to consider. 1) Is there a way to detect whether an overflow has occurred?, and 2) Are the results of an overflow predictable. I believe the answer to both of those questions is yes, and therefore, there should be a solution in there somewhere. :D.
gullymiles - saying something is "not a correct solution" isn't very helpful..there are any number of reasons a solution might not pass a test case. The question is - the algorithm can be correct, but be missing one thing which is causing the test case to fail. Sure, if you don't account for the overflow, the ultimate solution isn't "correct", but that doesn't mean the algorithm doesn't work. I would argue that if the algorythm works, then the solution IS correct, but it may not be efficient enough or smart enough about computer limitations (in the case of overflow) to pass. If the problem is efficiency, that often means needing to find a different solution, but that doesn't mean the solution isn't correct, it could be correct but insufficient. But again, that's the way I view it and at that point, it is more a question of semantics, because you are absolutely correct that if the goal is to pass the kata, there is more work to do.
@JJar could you please reply with your code? It doesn't display properly when I click on view solution to your comment.
I just compared the commented code to code by @IonutArhire.
On my computer, the commented code took 15.5 seconds to exicute on an array with 500'000 elements of length 4 and k = 1000. Code by IonutArhire took 0.081 seconds. I am amazed by the difference!
My code took 0.71 seconds which is 20 times faster than the commented code, but still 10 times slover than the code of @IonutArhire.
@IonutArhire, could you please let me know why your code is so much faster than mine?
That isn't an issue.
This is not a reason to retire a kata.
Loading more items...