Interview questions

Algorithm interview questions – page 18

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

  1. Given n number of xml files find a particular word and output should list all the files in current directory that contains that word.

  2. Write a program where you are given a number say N and you have to generate a random permutation of the numbers between 1 to N.

  3. There is a file with the following pattern

  4. How to convert positive number to negative and negative to positive

  5. Given nxn boolean matrix (0's and 1's) .

  6. What is the BEST-WORST case time to add and remove elements from a queue that has been implemented with the help of 2 stacks.

  7. You have a stream of innite queries (ie: real time Google search queries that people are entering). Describe how you would go about nding a good estimate of 1000 samples from this never ending set of data and then write code for it.

  8. Write a C program to compare two integers without using relational operators (== != < <= > >=)

  9. How will you design google map?

  10. Write an algorithm two divide two extremely large numbers, which cannot be stored in an int, long int, float, double etc. Find the remainder and quotient .

  11. Longest Common Prefix from N strings of max length "m". I gave a naive approach of O(n.m) and O(m.logn) with some adjustments but Interviewer wanted something O(n+m) or better than O(n.m). Please suggest solutions. eg: Flow...

  12. Write a func that will return second min weighted path between two nodes.(in linear time) Edge<list> find_sec( Node *n1, Node *n2, Edge<list> E2)

  13. Twenty seven identical white cubes are assembled into a single cube, the outside of which is painted black. The cube is then disassembled and the smaller cubes are thoroughly shuffled in a bag.

  14. Implement the Color filling of MS-paint (when u click on an image.. all the pixels connected with the same color are filled with the choosen color). Given a matrix nXn having values of a color at each element.. try to implement the color filling w...

  15. A graph is given. You need to design a data structure with minimum space complexity such that it does the follows --> Finds whether there is a path of length k between u and v in O(k) time --> Finds whether there is a path of l...

  16. Given a BST, write a function to return a node with the given value as data, if no such node then return a node with smallest data greater then the searched value!!!! Also design test cases for the same

  17. Given a book find out the number of times each word appeared. Upon clarification I was told the following things 1. punctuations should be removed 2. case sensitive 3. assume book is given as a huge string to the function prototype 4. Words need n...

  18. Given a sum s, and a number n as inputs, find out all possible combinations in order of n, summing up to s. For example: if s = 5, n = 2, then your program should print 0+5, 1+4, 2+3, 3+2, 4+1, 5+0

  19. Find the min and max in an array. Now do it in less than 2n comparisons. (they were looking for the solution that finds both max and min in about 3/2 n comparisons).

  20. Given a new input string, how would you search a suffix array to find the longest match in the stored text? How would you build a GUI interface for this task?

  21. Design an algorithm to find whether a given string is formed by the interleaving of two given strings or not.

  22. An any one explain me how this ternary search tree is built fro these striing shown

  23. Given an array of integers (possibly some of the elements negative), write a C program to find out the *maximum product* possible by adding 'n' consecutive integers in the array, n <= ARRAY_SIZE. Also give where in the array this sequence of n ...

  24. Given an histogram.. find out the maximum rectangle in it.. You are given the histogram as an array of heights of each bar.. find it in O(n)..

  25. How to find the two numbers whose difference is minimum among the set of numbers ? One solution is sort numbers and compare adjacent numbers to get minimum.. complexity O(nlogn).. Is there O(n) solution for this problem ?

  26. Assuming you are a unix/linux community developer Write the algorithm to simulate tail -n command of linux. n = number of lines to print. [FYI Tail -n will print out the last n lines of any file.]

  27. Display 15 to 150 on console. No loops, No conditional statements.

  28. How to generate the following series using recursion say for n(suppose n=4) print 4 3 2 1 2 3 4

  29. Given two unsorted int arrays, find the kth element in the merged, sorted array. example: int[] a= [3 1 7] int[] b = [4 9] k: 3 return 4.

  30. Write code that implements Huffman Coding

Companies that ask Algorithm questions