Does anyone actually do these tests in strongly typed languages?

Does anyone actually do these tests in strongly typed languages?

Too much time is spent converting data types and instantiating data structures.

>these tests
You mean, printf debugging?

It depends on the question. I'd happily spend 30 seconds extra on type conversion to get some debugging time back in those problems, unless the time to write the program in Python takes less than 30 seconds. For this, I would do the for example:

for i in range(max(input_list)):
if i not in input_list:
print(i)

That only took 10 seconds to write.

You clearly are, since you're using Python

Also your algorithm is shit. If you want time of O(N) and space of O(1), consider not using a list, and just looping through and summing all A values, and all A indexes (plus A since it's 0-indexed while the values are 1-indexed), then subtracting the former from the latter

Oops, I meant add length of A, plus length of A+1, as the values go up to length of A + 1

def solution(A):
len_A = len(A)
sumIndexes = 2 * len_A + 1
sumValues = 0

for i in xrange(len(A)):
sumIndexes += i
sumValues += A[i]

print sumIndexes - sumValues

The len(A) at the bottom should be len_A, just to save computation if it's not optimized already

O(N) space
O(N^2)
Nice

sum [0..n]=n*(n+1)/2

How do you even come up with this?

No one take the bait

>Too much time is spent converting data types and instantiating data structures
Ladies and gentlemen, the Javascript/Python generation programmers

The pattern is so easy to spot, it's laughable

>For example, I was doing an online test (not codility) where I had to get a space-delimited list of numbers from standard input, then do arithmetic with the numbers.

In Python it would be a simple call to input().

However, in C++ you first need to include a library for the input stream.
Then you have to prepare a list, and reserve sufficient space in memory.
Now that you have an empty list ready, you get one long string from the standard input.
You have to parse out each chunk, possibly using strtok().
So now you have a list of strings. You can't do arithmetic with that. You have to cast every value to an integer. This involves making ANOTHER list.

How the fuck is O(N^2)? It loops through every number from 1 to the maximum of the input list and looks if the number is in the list. That's as O(n) as it gets. (Checking if a list contains an item is O(1))

>Checking if a list contains an item is O(1))
Why do you say that? It's just a list, not a hash table or something.

>loop through all values in array
>loop through them again to see if it's in array
that's like n(n+1)/2 or n(n-1)/2 which is N^2

>(Checking if a list contains an item is O(1))
nope

maybe you should find the fault in layer 8, as it seems you have not yet completely understood the std libraries.

It's alright man, you're learning. I would make the same mistakes if I never did compsci. The worst thing to do when wrong is get angry and assert yourself

but it's only 1 item! therfore, o(1)

#include
#include

int main()
{
std::string str;
std::vector nums;
while (getline(std::cin, str, ' ')) {
nums.push_back(std::atoi(str.c_str()));
}

// do stuff

return 0;
}


maybe you don't understand the language well enough