Interview questions

Algorithm interview questions – page 7

811 questions. Tap “Show answer” to check yourself.

  1. Suppose you are a search engine owner and want to show adv to make money. How will you filter the advertisements to be shown when users searches for something. Take into consideration that advertisers will not be interested in showing adds to all ...

  2. I found this puzzle here http://shashank7s.blogspot.com/2011/07/my-design-problem-1-man-party-puzzle.html

  3. There is a town which is a square grid.. every point can be reached from any other point.. there are 10 peoples in the grid.. find a common meeting ground for them such that the total distance travelled by those 10 people are the least

  4. Give a set of phone numbers. How to check if there are any duplicates.

  5. A matrix(m*n) full of chars, find all possible words in it. You can go in any direction, left right top bottom, Find out all English valid words, same index should not occur twice in same word

  6. Offered an infinite stream of bits with the bits getting appended at the best important placement. give an algorithm to to say whether the amount formed by employing the sequence of bits that had been processed till then, is divisible by 3 or not?...

  7. Given 2 trees A and B, write a function that determines whether tree B is a subtree of Tree A or not. Provide the time complexity of the solution.

  8. Given two input texts, find the longest string that occurs in both.

  9. U have got an array of size 2n+2 of which there are n pairs and remaining two are unique. How to find them in less than O(nlogn) time and constant space

  10. Given an array of elements find the largest possible number that can be formed by using the elements of the array.

  11. You are given three files. The files contain data of orders placed by thousands of customes. Find the common customer names in three files.

  12. You have an array. For eg [23,12,45,23,9,23,45] Now you have to print the elements in the order of decreasing frequency, and the same no of times as it is coming in the imput aray. So the output for this eg would me [23,23,23,45,45,12,9].<b...

  13. Write a program to merge two BST efficiently in O(n)

  14. A chessboard of size 64 blocks is given. a knight can move two n half moves at a time..how many steps will it take to cover all the 64 blocks...and change the algorithm if the knight moves three and a half moves.

  15. A binary tree problem - Populating next right pointers in each node

  16. Consider there is an array with duplicates and u r given two numbers as input and u have to return the minimum distance between the two in the array with minimum complexity.

  17. Write a function that computes log2() using sqrt().

  18. For a given matrix NxN having 0 or 1s only. You have to find the count of rows and columns where atleast one 1 occurs.

  19. Design a data structure for storing sparse arrays. Implement multiplications of such arrays

  20. Write a function print(int n) which prints the values of n, 2n, 4n, 8n ... till the value doesn't exceed 40000. After reaching 40000, it it should print 8x, 4n, 2n, n. No local variables, no loop and no GOTO

  21. Function rand(n) generate random number between 0 to n-1 . Find the number of collision to generate each of the numbers between 0 to n-1 . Write an algorithm to reduce the number of collision to o(n)

  22. Infix expression is given and Convert infix expression to postfix expression and write a tree also.

  23. Assume that your friend is writing a book. He gives you a file that contains that book. Your job is to develop an algorithm for indexing of that book. In every book there is one index at end which contains some words which are not there in normal ...

  24. Given millions of time intervals, compute the maximum weights and the time when maximum weights occurred.

  25. Two very large numbers are represented using arrays. Multiply these two numbers. E.g. Two numbers 12 and 13 are represented as a=[1,2] adn b=[1,3]. The expected result is 12*13=156 i.e. c=[1,5,6]

  26. Write a program .. A set is given ,find all subset which sums to a given number.

  27. You are given a stream of bits (0 or 1), program an approach that prints "Multiple of 3" when the binary stream becomes multiple of 3.

  28. Convert a BST to a sorted doubly linked list in-place.

  29. Given two sets, Write a function to provide the union of them. STL not allowed to be used. Optimise for Time and space

  30. Given a number 123456789 and two opearators + and *. You can use this two operators as many times u want. But you cant change the sequence of the number given there. The evaluated value is 2097.

Companies that ask Algorithm questions