Retour au sujet

Avatar de HylienDivin HylienDivin 🙋🏻
Je partage un test de code / maths que j'ai eu récemment pour une entreprise à laquelle j'ai postulé.
----------------------------------------------------------------------

Hello Antoine,

Thank you for your interest in our team! Below are three brief coding tests we'd like you to try. Please complete and send us your solutions using the link below. We are looking for a program (not a notebook) that can be called from the command-line using a Python interpreter. Please submit the Python source code files directly to Greenhouse, do not submit any compiled code and do not submit as an archive (e.g. “.zip”.)

We ask that you please take no more than a week, ideally less, to return this to us. If you need more time for some reason, let us know.

We look forward to hearing from you.

Regards,

Ghibli Recruiting Team




Problem 1.

Write a Python function that takes numpy array of booleans and returns a numpy array of type int64. The i-th element in the resulting array should contain the distance from the closest true in the input array at or before position i. The resulting array should have a -1 if there is no True value at the current or any previous position. The input array size will be on the order of 1e8, number of true value is of the order of 1e7. Implementation with python loop over all elements or over all true values is not considered sufficiently efficient.

Problem 2.

Write python code that performs the following calculation.

Given numpy array A[i] of length N and positive constants w (N/10<=w<=N), h1 (h1>=N/2) and h2 compute an array of the same length.

B[i] = sum(A[j]*exp(-(i-j)/h1)*cos((i-j)/h2); i-w<j<=i, j>=0).

The code should only use numpy library. The code should be vectorized and the algorithm should be asymptotically linear in the length of the array and should avoid python loops. Note that numpy.convolve uses an algorithm with quadratic complexity.

Problem 3.

Write Python code that performs the following computation.

Given a numpy length N floating point array A (1<=A[i]<=2) and a numpy length N integer array S (0<=S[i]<=i), return length N floating point numpy array X with elements X[i] = sum of A[k] * exp(-50*k/N)) for k in range S[i]<=k<=i.

The value of N is around 100000000. Implementation with python loop over all elements is not considered sufficiently efficient.

Include a unit test that checks relative error of output of your solution for N=20 against an output of a simple solution that accumulates all sums explicitly.