Interview questions

Algorithm interview questions

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

  1. How to swap all the values without using temporary variable. tha values r a = 20, x=60 and p=2.

  2. How Many Algorithms You Can Do Perfectly ?

  3. A non-empty zero-indexed array A consisting of N integers is given. The first covering prefix of array A is the smallest integer P such that $0 leq P < N$ and such that every value that occurs in array A also occurs in sequence $A[0], A[1], l...

  4. Given two Arrays {a1,a2,a3,.ai...aj...an} {b1,b2,b3,...bi...bj...bn). Note the size of both arrays are same.. We have to arrange the arrays in such a way such that aibi > ajbj. and ai > bi and aj > bj.

  5. Quick-sort is run on two inputs shown below to sort in ascending order (i) 1,2,3, .,n (ii) n, n - 1, n - 2, ., 2, 1 Let C1 and C2 be the number of comparisons made for the inputs (i) and (ii) respectively. Then,

  6. What are NP complete and NP hard problems?

  7. Vankins Mile is a solitaire game played on an n X n square grid. The player starts by placing a token on any square of the grid. Then on each turn, the player moves the token either one square to the right or one square down. The game ends when...

  8. Given an array of 2n elements of which n elements are same and the remaining n elements are all different. Write a C program to find out the value which is present n times in the array

  9. Test cases for vending machine

  10. Given an expression get rid of the pointless brackets in it with out making an ambiguity in its execution. input output ex1: (a+(b)+c) a+b+c

  11. Print prime factors of an integer and count of each of those.

  12. Reverse the words in a sentence. The string "have a nice day" should be changed to "day nice a have".

  13. Given a fair coin, make an unfair coin that head with p probability and tail with (1-p) probability where 0 < p < 1.

  14. You have millions of lines of data. 2 lines are identical, the rest are unique. Some lines are so long, that they do not fit in memory. How would you find those 2 identical lines?

  15. Write a code for minimal spanning tree

  16. Suppose you are given an infinite series of strings, each at a certain position as follows: 1. a 2. b 3. c 4. d .. 26.z 27.aa 28.ab .. 52.az

  17. Given an array A[] and a integer K. Find the combination of four no's in the array whose sum is equal to K.

  18. Which is of the sorting algos is memory inefficient? Quick, merge, bubble.

  19. Given an array of numbers : a1, a2, a3... an... (a) divide them in such a way that every alternate segment is given to two persons john and mary, equally,null,,null, the number of segments made should be minimum... eg...<br ...>

  20. Imagine a (literal) stack of plates. If the stack gets too high, it might topple. Therefore, in real life, we would likely start a new stack when the previous stack exceeds some threshold. Implement a data structure SetOfStacks that mimics t...

  21. There is a parking lot of cars that is full except for a single spot. Write some code to take it from one arbitrary configuration to another moving only one car at a time into the empty spot.

  22. Write a program to swap to integer pointers

  23. Describe an algorithm to find the largest 1 million numbers in 1 billion numbers. Assume hat the computer memory can hold all one billion numbers.

  24. You are given an array of positive integers. Convert it to a sorted array with minimum cost (minimum number of operations). Only valid operation are 1) Decrement -> cost = 1 2) Delete an element completely from the array -> cost ...

  25. Given a file with a lot of words (10 million) find out the top 10% most frequently occurring words.

  26. Merge two binary search trees into one

  27. Given that an array consists of only 0s, 1s, and 2s, sort it. Again, only very efficient code was accepted. Good old counting sort was sneered at. He wanted an algo to do this in one pass of the algorithm without using any extra space, and which p...

  28. Given an integer n , you have to print all the ways in which n can be represented as sum of positive integers.

  29. You have 1 billion numbers and 2 GB ram. You need to sort them. Now the interviewer gave conditions 1) in memory sorting, 2) using bit vector or bit operands

  30. You are given a list of points in the plane, write a program that outputs each point along with the three other points that are closest to it. These three points ordered by distance. The order is less then O(n^2). For example, given a set of point...

Companies that ask Algorithm questions