Data Science Interview Questions

10,851 data science interview questions shared by candidates

The second question asks you to refactor a function in O(n^2) and make it O(n), basically by eliminating the nested for-loop. This is the function you're asked to refactor: int solution(int *A, int N) { int result = 0; int i, j; for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (A[i] == A[j]) if (abs(i - j) > result) result = abs(i - j); return result; }
avatar

Computer Science Intern

Interviewed at Spire Global

2.7
May 18, 2015

The second question asks you to refactor a function in O(n^2) and make it O(n), basically by eliminating the nested for-loop. This is the function you're asked to refactor: int solution(int *A, int N) { int result = 0; int i, j; for (i = 0; i < N; i++) for (j = 0; j < N; j++) if (A[i] == A[j]) if (abs(i - j) > result) result = abs(i - j); return result; }

Viewing 11 - 20 interview questions

Glassdoor has 10,851 interview questions and reports from Data science interviews. Prepare for your interview. Get hired. Love your job.