Computer Science Internship Interview Questions

478 computer science internship 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
18 May 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; }

You are given a Binary Search Tree of ints with duplicate entries. You are guaranteed that if an element has a duplicate entry, it is in the right subtree of that element. Write a function to count the total number of duplicates. (note, if a tree contains the same element two times, the count of duplicates is 1, not 2)
avatar

Computer Science Intern

Interviewed at Amazon

3.5
18 Jan 2012

You are given a Binary Search Tree of ints with duplicate entries. You are guaranteed that if an element has a duplicate entry, it is in the right subtree of that element. Write a function to count the total number of duplicates. (note, if a tree contains the same element two times, the count of duplicates is 1, not 2)

Viewing 1 - 10 interview questions

Glassdoor has 478 interview questions and reports from Computer science internship interviews. Prepare for your interview. Get hired. Love your job.