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.
Wow!! Absoulately clever!!
This comment is hidden because it contains spoiler information about the solution
that doesn't change the time complexity: you're comparing things like
3*1
and1*3
.When you don't know, ask for information, rather than downvote people who are explaining to you that you're making a mistake.
Pretty clever solution :)
Although I want to highlight you end up traversing the main string thrice.
This is beautiful, best code I saw today :)
This solution is very elegant, I'm not not sure how much more expensive is this solution compared to just iterating twice over the input string. Also amount of additional space complexity involved with the new strings that are created. Does any one have an idea?
Ideally it should be something like this:
int remainingPages = itemCount() % itemsPerPage;
if(remainingPages == 0 || pageIndex < pageCount() - 1) return itemsPerPage;
else return remainingPages;
I noticed too, this solution will fail for scenarios when itemsPerPage completely divides totalPages
Check this out: https://en.m.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations#Matrix_algebra
It's possible to do with lower complexity, but I don't know whether the listed method is considered elegant.
Not sure whether to mark this as spoiler or not...
Is there a elegant solution with better complexity? I see most solutions have complexity O(N^3) including mine.
This is neat using a single loop, but has a slighly higher time complexity involved with using replace function.
I agree this is a cool solution but far from following best practices. Runtime complexity for this solution is O(N^2) which can easily be solved in O(N)
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution