Interview questions

Algorithm interview questions – page 15

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

  1. Given an array A of positive integers. Convert it to a sorted array with minimum cost. The only valid operation are: 1) Decrement with cost = 1 2) Delete an element completely from the array with cost = value of element

  2. Given an integer, write a function to check whether the binary representation of the integer is palindrome.

  3. Generate and print power set of a set

  4. Find a 8-digit number, where the first figure defines the count of zeros in this number, the second figure the count of numeral 1 in this number and so on...

  5. Given two integers a, b how to divide (a/b) without using / and % operators (repeated subtraction is not the solution).

  6. You have m nuts and n bolts, Every unique nut is fit in every unique bolt, Suggest an effective algorithm for placing each nut in each bolt in less no. of passes?

  7. Given an Infinitely long rail track and two robots.

  8. No of multipication required ti calculate x^n? i. n ii. logn iii. n/2 iv. n^2

  9. Given a string or a sentence write a function to split the string on the basis of occurrences of white spaces. Note that occurrences of multiple white spaces will be counted as one. Do not use extra arrays for storing the split strings. Also do no...

  10. What is the time and space complexities of merge sort and when is it preferred over quick sort?

  11. Given an unsorted array of integer for each value at each index i u have to swap it 1st small value after value at ith index in O(N)

  12. You have given a dictionary and a string, you need to separate words that are in dictionary. ex - catsanddog (here cat and cats both can be in dictionary) output - cat,cats,sand,dog

  13. Really like the linear solution of this problem. You have an array of 0s and 1s and you want to output all the intervals (i, j) where the number of 0s and numbers of 1s are equal.

  14. You have n strings with their lengths. You are given an add(string s1,string s2) which would concatenate the string s2 with s1 and return s3. Optimize the cost of concatenation of all these strings into one big string. Ex: 1,3,2 are the leng...

  15. Pick two data structures to use for implementing a Map. * Describe lookup, insert, & delete operations. * Give time & space complexity for each. * Give pros & cons for each.

  16. Can all recursive pgms be written iteratively?

  17. Given a list of words and a list of search words Find the smallest sub list which has all the search words

  18. Consider a row of n coins of values v(1) ... v(n), where n is even. We play a game against an opponent by alternating turns. In each turn, a player selects either the first or last coin from the row, removes it from the row permanently, and receiv...

  19. Write efficient program to find the number of divisors of number what is the time complexity of finding the number of devisors of a number..?

  20. Given two Points P1(x1, y1), P2(x2, y2) given a function to draw a point draw(double x, double y) and also x2>x1 write an algorithm to draw line.

  21. Let A be a real valued matrix of order n*n already stored in memory. Its (i, j)-th element is denoted by a[i, j]. The elements of the matrix A satisfy the following property:

  22. U know the max number and min number is always zero.. u will be given pairs.. u need to see whether they have any gaps.. ex1: max no:20 pairs: 11-15, 0-5, 18-20, 14-19, 6-13

  23. Suppose you have a M-by-N matrix (i.e. M rows and N columns), whose entries are all integers. Set all the elements of the j-th row and k-th column to 0 if matrix[k][j] is 1.

  24. Write a C program to create a bitmap of any size as determined by user. Say user says 64k bitmap, then create 64k long bitmap. Have set and unset methods.

  25. You are given n strings. You have to find whether a chain can be formed with all the strings given namely n ? A chain can be formed between 2 strings if last character of the 1st string matches with the first character of the second string. ...

  26. How would you find out if a number is prime in minimum time.

  27. You have a sequence where each number is a multiple of 2 or 5 (so: 2^i * 5^j). Given the beginning of the sequence as 1,2,4,5,8,10,16... and find a algorithm to calculate the next number in the sequence?

  28. - Without using /, % and * operators. write a function to divide a number by 3. char *itoa(int) function is available.

  29. Given an Integer array, find the maximum difference between any of the iterators 'i' and 'j' such that Array[i] < Array[j] and i < j

  30. In this, for 75% times A>B and 25% times B>C then, in 10000 instructions F to G [a] 7500:2500 [b] 7500:625 [c] 7500:625 if a=b=c else 7500:2500

Companies that ask Algorithm questions