Coding Interview Questions | Glassdoor

Coding Interview Questions


interview questions shared by candidates

Coding Interview Questions

Sort: RelevancePopular Date

Suppose you have a matrix of numbers. How can you easily compute the sum of any rectangle (i.e. a range [row_start, row_end, col_start, col_end]) of those numbers? How would you code this?

6 Answers

It can be done in constant time by precalculating sums of some basic rectangles (extending all the way to the border of the matrix). That precalculation times time O(n) by simple dynamic programming.

Please elaborate, which "basic rectangles"? Are you recursively dividing each rectangle into 4 smaller rectangles? Precalc time for doing that is not O(n)?!?

Compute the sum of the rectangles, for all i,j, bounded by (i,j), (i,m), (n,j), (n,m), where (n,m) is the size of the matrix M. Call that sum s(i,j). You can calculate s(i,j) by dynamic programming: s(i,j) = M(i,j) + s(i+1,j) + s(i,j+1) - s(i+1,j+1). And the sum of any rectangle can be computed from s(i,j).

Implement a function to validate whether a given binary tree is a BST (i.e. write an isBST() function).

9 Answers

Write a function that divides two numbers without using the divide '/' operator.

10 Answers

Write a function that takes 2 arguments: a binary tree and an integer n, it should return the n-th element in the inorder traversal of the binary tree.

7 Answers

You are a parking lot attendant in a lot that has one open spot, and you want to move the cars from their original positions into a new arrangement. Create a program that will print out instructions on how to move the cars most efficiently.

7 Answers

Given a list of integers, some of which may be negative, extract the pair that sums to the largest number.

8 Answers

Initialize a 5 by 5 array with this sequence. 1 2 3 4 5 6 4 8 9 10 11 12 9 14 15 16 17 18 16 20 21 22 23 24 25

7 Answers

Look for a string in a very long string - a needle in a haystack. Write the program in pseudo-code.

5 Answers

I am playing a card game called 24. Cards ace to king are numbered 1 to 13. During a given round, I am provided four cards to play with from the shuffled pack. If the numbers from the four cards result in 24 then I win the round if I shout '24' first. How would you code a function for this?

4 Answers

Extract the N largest floating point numbers from a large file of floating point numbers.

4 Answers
110 of 70 Interview Questions