Let's start with some general remarks: Swift does not require semicolons after statements (but they are allowed). From what I have seen since Swift was introduced last year, most people do not write ...

There is some room for improvement in your code, and I will try to explain that in several steps. But please note that I am not a C# person, so my review refers only to the algorithm and performance ...

First I would choose a different representation of the colors during the computation, to avoid the “expensive” COLORS-{a, b}).pop() operation, which is executed $$(n-1) + (n-2) + \ldots + 1 = \... View answer 19 votes Your code looks good to me, and I have only some minor remarks and suggestions. An Optional has an implicit initial value of nil, so var retnValue: String? = nil can be simplified to var ... View answer Accepted answer 18 votes Correctness Your function reduces 0/0 to 0, but the result should be "undefined" or "invalid". Too many special cases Your function distinguishes far too many cases. The process of simplifying a ... View answer 18 votes Your usage of auxiliary functions is not consistent: Some computations are done inline, e.g. int hours = totalSeconds / MINUTES_IN_AN_HOUR / SECONDS_IN_A_MINUTE; and other (equally simple) ... View answer 17 votes Your algorithm tries to find the largest factors first. This is ineffective because you have to test each possible factor whether it is a prime number or not. It is much more effective to start with ... View answer Accepted answer 16 votes The following is similar to Flambino's approach, but creates a Swift SequenceType so that you can use the Swift library functions filter() and reduce() to iterate over the elements: struct ... View answer Accepted answer 14 votes I can see no advantage of computing the hash value from Int(self.x) and Int(self.y). As you already noticed, truncating the floating point numbers to integers loses information and therefore causes ... View answer 14 votes if(dimension == 0) { return 0; } Mathematically, that is not correct. The determinant of an empty (i.e. zero-dimensional) matrix is one, see for example What is the determinant of []? on ... View answer Accepted answer 14 votes There is an error in your countDivisors() function, the result is one too large for a perfect square, i.e. countDivisors(25) returns 4 instead of 3. Also the loop variable i should be a long to avoid ... View answer Accepted answer 13 votes What you are approximating is$$ \pi =\sum_{m=1}^{\infty}\frac{(-1)^{s(m)}}{m}, where $s(m)$ counts the number of appearances of primes of the form $4k+1$ in the prime decomposition of $m$, ...

iA and iB can only take the values 0 and 1, so that if ((1 == iA || 1 == iB) && (1 != iA || 1 != iB)) { ... } can be simplified to if (iA != iB) { ... } Boolean variables would be more ...

Validate the input: At present, your program aborts with IndexError if called without arguments, aborts with ValueError if called with a non-integer argument, prints None if called with an integer ...

Your function uses global variables, which is bad for several reasons: The variables must be reset before the function can be called again. The variables can be modified from outside of your function,...

First of all, the PrimeFactorize() does never terminate for number = 1 because the check IntUtils.IsPrime(number) will never return true. The call PrimeFactorize(1) should return an empty list. To ...

If a program fails for some reason then it should Write a diagnostic message to standard error (not standard output), so that it can not be mistaken for normal output, e.g. when the program runs in a ...

That is not the Sieve of Eratosthenes The Sieve of Eratosthenes computes multiples of each found prime to mark subsequent composite numbers in the sieve. Your algorithm computes the remainder of all ...

Bugs The loop for (let i = 0; i < tempArray.length - 1 ; i++) { omits the last array element, it should be for (let i = 0; i < tempArray.length ; i++) { If all array elements have the same ...

Spacing The usage of (horizontal) space is not consistent, you have a space after if and switch, but not after else and while. I would generally use more whitespace to increase the readability, in ...

First I would suggest to separate the code into two functions: One which computes the sum of odd divisors of a single number, and another which adds the odd divisors of all numbers in a list. Also, ...

Your code tries all $n (n+1)/2$ combinations of array elements to find the combination with the largest sum, so the complexity is $O(n^2)$. A better solution would be to find the two largest ...

Using a property for the boolean attribute is fine. Properties have many advantages: they encapsulate an objects value (i.e. the actual implementation is hidden from the outside, it need not be an ...

Do not silently ignore invalid arguments Your script allows to specify the source directory (and other locations). Here is the relevant part in function parseArgs(): -s|--src) ...

The “set or increment dictionary value” logic freq = {} for i in s: if i in freq: freq[i] +=1 else: freq[i] = 1 can be simplified using a defaultdict: from collections ...

Unfortunately, it does not work correctly. The output is 0 (zero rooms) for the floor plan 4 6 ###### #.#..# #....# ###### After parsing the second row, the room count is two and the tracker vector ...

You want to compute the largest prime factor of a given number, but it is actually more efficient to look for the smallest prime factors first (and I am just repeating my arguments from my answer). If ...

This #include <bits/stdc++.h> using namespace std; is given by the submission template from HackerRank (so it is not your fault), but note that both lines are generally considered as bad ...