Interview questions

Algorithm interview questions – page 3

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

  1. If the Fibonacci series is 1, 2, 3, 5, 8, 13,... then 10 can be written as 8 + 2 ==> 10010 and 17 can be written as 13 + 3 + 1 ==> 100101.

  2. Given a dictionary of millions of words, write a program to find the largest possible rectangle of letters such that every row forms a word (reading left to right) and every column forms a word (reading top to bottom). Anyone got any ideas? ...

  3. 3 divides 111 , 13 divides 111111 etc.. find a number having all one's which is shortest divisible by a given number which has 3 as its last digit.

  4. You have to write a function checkRegex() which takes two strings as input, one string represents a regex expression and other is an input string to match with the regex expression passed as the other parameter. Return true if it matches, else fal...

  5. What are the different ways to say, the value of x can be either a 0 or a 1. Apparently the if then else solution has a jump when written out in assembly.

  6. Write a C function for unsigned power(double x, unsigned int n) using minimum number of multiplications. Count the number of multiplications used.

  7. Write a code that will check whether the memory allotted to the program at the initial and the memory returned to the system is same or not.

  8. You are given a function (say func1). When it is called, it returns 0 with 60% probability, and 1 with 40% probability. Now using this function, write a new function(say func2) that returns 0 with 50% probability and 1 with 50% probability.

  9. Given an array of size n wherein elements keep on increasing monotonically upto a certain location after which they keep on decreasing monotonically, then again keep on increasing, then decreasing again and so on. Sort the array in O(n) and O(1). ...

  10. I have an array consisting of 2n+1 elements. n elements in it are married, i.e they occur twice in the array, however there is one element which only appears once in the array. I need to find that number in a single pass using constant memory. {a...

  11. Given a matrix of characters M and an input string S, find if S occurs in M in horizontal or vertical direction.

  12. You are given a 1D array of integers, such as: int[] array = [3,4,7,2,2,6,0,9]; Suppose you need to treat this array as a 2D table with a given number of rows. You want to sum the columns of the table. One value of numRows ...

  13. In a university, students can enroll in different courses. A student may enroll for more than one course. Both students and courses can be identified by IDs given to them. Design a data structure to store students, courses, and the student-course ...

  14. Create a fast cached storage mechanism that, given a limitation on the amount of cache memory, will ensure that only the least recently used items are discarded when the cache memory is reached when inserting a new item. It supports 2 functions: S...

  15. Given a N x N matrix, find the median. the matrix is sorted row-wise and column-wise

  16. Given an integer array of which both first half and second half are sorted. Write a function to merge the two parts to create one single sorted array in place [do not use any extra space]. e.g. If input array is [1,3,6,8,-5,-2,3,8] It should...

  17. What data structure would you use to implement a routing table? Suggest optimizations.

  18. U have got 3 sorted arrays A1 A2 and A3 having m n and p elements respectively. A gap of 3 arrays is defined to be max distance between 3 nos if they are put on a no line say u pick three 2 12 and 7 then the gap is 10. Now u have to find an effici...

  19. A sequence of numbers is coming ... a) find in constant time if a number has already come b) find in constant time how many time a number has come

  20. If the sum of the roots of the equation ax2 + bx + c=0 is equal to the sum of the squares of their reciprocals then a/c, b/a, c/b are in

  21. You have given a positive number you have to find a number which is bigger than that by using same digits available in the number. Example :- You have given a number 7585 , your output should be 7855 .

  22. Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2) without making use of any floating point computations at all

  23. Consider a huge feed of data like the case of twitter or facebook. Now, how would you go about implementing search (ads) based on keywords. So someone tweets (Want to buy watch) ads to be shown should be relevant.

  24. Implement function to find needle from a haystack. Interviewer was looking for coding skills.

  25. A recursive loop for fibonnaci was given as follows

  26. Given 3 input strings S1, S2, S3 for example take s1 = "hard" s2 = "work", s3 = "success" assign numeric values (0-9) to each of the characters in these strings such that equation s1 + s2 = s3 holds true. Constraints are that all occurrence ...

  27. You have 50,000 html files, some of which contain phone numbers. How would you create a list of all the files which contain phone numbers?

  28. Write a function that accepts a string as parameter and check if the string is an integer. if the string is integer then return the integer value.

  29. We are given a set X = {x1, x2, ..., xn} where xi = 2i. A sample S (which is a subset of X) is drawn by selecting each xi independently with probability pi = 1 / 2. The expected value of the smallest number in sample S is: a) 1 / n<br ...>

  30. Imagine a disk spinning like a record player turn table. Half of the disk is black and the other is white. Assume you have an unlimited number of color sensors. How many sensors would you have to place around the disk to determine the direction th...

Companies that ask Algorithm questions