Approved some time ago
I tested HashSet with the test runner of Code Wars:
With HashSet: under 1s,
HashSet is 6 times faster.
You can use https://docs.microsoft.com/ru-ru/dotnet/api/system.string.join?view=netcore-3.1#System_String_Join__1_System_String_System_Collections_Generic_IEnumerable___0__
and not convert result to array.
I think ice19942335's profiling code is mostly right in the sense that conceptually everything is done right. But the there are technical issues such as:
I would like have think in this before i made the worst code as possible, very very clever sir
Try to avoid mutable variables in F# when possible. For this example, the explicit mutation is not necessary.
you're passed a list of coordinates, each an instance of this class:
def __init__(self, x, y):
self.X = x
self.Y = y
so you access the instance attributes with .X and .Y
how can I access the given points? Are they tuple or what?
In given code in the screenshot, you're computing Array.FindAll() and HashSet.Contains togather! As Microsoft states access order for HashSet<>.Contains is always O(1) which is far better than finding elements in array using Array.Contains method which has worse case of O(n).
As every interviewer recommends, use Dictionary<,> or HashSet<> in interview problems to access stored values where possible to reduce time order in your solution.
Hey mate! How are you?
Look at this - https://c2n.me/43LRqF8.png
I did some test hire. And as we can see hashSet isn't faster.
Correct me if I did my test wrong.
I agree, it took me ages to figure out an algorithm that was efficient enough to pass the tests.
This cata should has a score higher then 5.
For c# this solution actually includes the dividebyZeroException that was asked
The current method signature is incorrect because of two reasons (see the task description):
I would declare the alphabet string as a constant above the return so it gets allocated to memory once, rather than everytime you perform a select; this is only a memory performance enhancement and would not alter the result in any way.