Interview questions

Algorithm interview questions – page 4

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

  1. Function to get count of primes in range 1..n

  2. Find the minimum number of queens required so that every square grid on the chess board is under the attack of a queen. Arrange this minimum no. of Queens on a chess board.

  3. I am on yahoo mail and start a forward thread to all my contacts. How long will it take for the same gossip to travel back to me?

  4. Given really large (beyond normal memory limits) data in some sort of tokenized format, write code to print top "n" frequently occurring data.

  5. A sequence of words are coming ... a) you need to find if a particular word has already occurred in the series .. b) complexity should be proportional to the size of the word that is being scanned ...

  6. Write a logic to add the digits of an integer, get the sum and again add the digits of the resulted sum. Keep on doing this until the sum reaches to single digit. Ex: number : 3456257672 sum of digits:47 result sum : 47 sum of ...

  7. How you will find the lowest common ancestor(LCA) in Binary Tree..its clear its Binary Tree not The4 Binary Search Tree ?

  8. Given a matrix (2D array) of m x n elements (m rows, n columns), write a function that prints the elements in the array in a spiral manner. Sample input matrix: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22...

  9. How time complexity of recursive is calculated? calculate time complexity of tree traversal algos

  10. Write a function that can count the number of children for each node in a n-tree. A node can have any number of children.

  11. Prove The Time Complexity of Sieve of Eratosthenes (prime generation algorithm()) is O(nlog(logn))..Interview wants from clean Mathematical Proof..for this..

  12. Find the most frequent element in an array

  13. I have a file in which there are supposed to be 4 billion numbers, starting from 1 to 4,000,000,000 but unfortunately one number is missing, i.e there are only 3,999,999,999 numbers, I need to find the missing number.

  14. There exists 2D char array.. we need to find out whether a given string("microsoft") exists in the given matrix. the string can be vertical or horizontal..but NOT diagonal. it can also be in this form..(like the snake in the cell games ) m i...

  15. Write a function to find the longest common prefix string amongst an array of strings

  16. How will you implement pow(a,b) without using multiplication or division operators. You can use only add/substract operators.

  17. - You are given two 4 digits prime numbers N1 and N2, - You can change only one digit of N1 at a time. - Resultant of changing a digit of N1 should also be a prime number.

  18. There is a list containing the checkin and checkout time of every person in a party . The checkin time is in ascending order while the checkout is random .

  19. Write code to find Inorder Predecessor in BST (you don't have parent pointer)

  20. How to reduce the no of calls.. to malloc()... to allocate a 2-d array.

  21. Compress the given string eg. aaabbcccaadee o/p = a3b2c3de2

  22. There is an integer array consisting positive and negative integers. Find maximum positive difference S defined as:

  23. Card shuffle problem. I have a card pack of 313 cards. I remove the topmost card from card pack and place it on desk and I remove the next one and put it below the pack of cards(that you are holding). keep doing this till all the cards are on desk...

  24. Which of the following is TRUE about the declaration const char * p a. the pointer cannot be changed but the value to which it points can be changed b. the value is constant but the pointer can be changed c. neither the value nor...

  25. The input number is n. Find the closest Fibonacci series number i where i < n. Show the time complexity of the problem. For eg : if n = 10, the output "i" should be 8

  26. Streaming byte data coming which can be intergers or characters, you have to sort both the integers and characters with there index intact. for e.g you have c6b2e4a your sorted array should be a2b4c6e

  27. A tree is serialized in such a way that all the leaves are market with L and all the other nodes with N. The tree is serialized keeping the order derived by a pre-order traversal. Write an algorithm for reconstructing the tree. Also, suggest a met...

  28. Give a non recursive algorithm that performs an inorder traversal without using a stack or any extra space.

  29. Suppose a matrix A (M*N) is given . And A is defined as ..

  30. You have a note to write by cutting and pasting necessary letters from the book, write an algorithm to see if you can write the note.

Companies that ask Algorithm questions