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 will not work for non English letter
Have you actually tried testing that claim? I've tested 5 solutions (mine, the linq solution commented on, yours and two others from this comment thread). Only one commenter I tested in this thread (zokeer) has a solution that actually runs faster than the Linq solutions (though at least all the solutions run in linear time against varying string lengths and varying unique character amounts). Both yours and Zub_Son's are slower than the Linq solutions despite commenting on the alleged slowness of it.
Not only are the Linq solutions easier to write and read, this shows that most people trying to make faster/more optimized solutions end up slower than the naive Linq one. Add in that such optimizations aren't really necessary unless the method is an a hot path and I'll prefer a competently written short Linq solution 90% of the time.
Both your and this solution run in linear time, so I'm not sure why you'd think this is inefficient in terms O-Notation. Your solution is roughly two times faster than both this and my Linq solution in my tests (string length of 650, 6500 and 65000) but all three solutions scale linearly. The Linq solutions also allocate more space but unless this function represents a performance bottleneck I would 100% prefer a short and easy to read/write Linq expression over doing it by hand.
I mostly like this, only thing i feel is off is PageItemCount() as it's susceptible to becoming a trainwreck and is kinda hard to read. Other than that I like this.
Once again I have been convinced that I should learn Linq, lol.
it is short but very suboptimal unfortunately - this forces unnecessary calcualtion of square number... if the array is large then it is very inefficient. Manual squre is the way as it allows to return false if the first one or any is false, rather than doing all the calculations beforehand.
Absolutely not a "best practice" because of the way Dictionary is used.
Since a while, .Net take care of the order of insertion, but it is not specify and can change at any time.
A dictionary is meaned to store a relation between keys and values, not the order of keys.
The usage of anonymous class or Tuple would be far better.
The rest is perfect.
This comment is hidden because it contains spoiler information about the solution
This is tricky.
new String
will never be interned if not interned explicitly, because it is, well,new
-ed. So it's always new in the beginning, you will not get an interned instance by callingnew
(it can be interned later, but details are not simple). But. C# has the concept of operator overloading (unlike Java), and it overloads theoperator ==
for many value types, including string. That's whystr1 == str2
performs value equality check, and not a reference equality check.new String("") == ""
will always returntrue
. But. The example you showed does not perform a string equality check. It compares anobject
with astring
, so the overloadedString.operator ==
does not kick in. The comparison is a reference equality check, and, in this case, it will returntrue
only when checking equality of interned string instances.This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
In this kata we have the example:
"var helper = new PaginationHelper(new List{'a', 'b', 'c', 'd', 'e', 'f'}, 4);
helper.PageCount; // should == 2
helper.ItemCount; // should == 6
helper.PageItemCount(0); // should == 4"
But you can't use it like this:
helper.PageCount; // should == 2
helper.ItemCount; // should == 6
Those are props - not a method!
And this kata is stupid. I wrote my code - and pass all 17 test and then pass 63 from 65 when was trying to submit. So - i rewrite it twice - but the same result - 63 tests were good. In my ps i couldn't reproduce any errors - so - i picked up this solution.
This is the first time i use someone's solution - but thit kata is so lame!
I know how to solve it - but they said - that it didn't pass some misterrious tests - i don't even know what kind of tests...
So, i got 63 from 65 =)
With love =)
I like the way you calculated years and so on.
I did the solution with over 40 lines of code and time complexity was still O(N log (n) ), so looking at this solution is embarrasing
Great minds think alike! This is pretty much identical to what I came up with!
Loading more items...