Interview questions
Algorithm interview questions – page 14
811 questions. Tap “Show answer” to check yourself.
-
Given a set of numbers eg:{2,3,6,7,8} . any one who is playing the game can score points only from this set using the numbers in that set. given a number, print all the possible ways of scoring that many points. Repetition of combinations are not ...
-
Given an unsorted array of numbers, Find a set of all the pythagorean triplets. e.g. Input array: [12,3,5,8,9,15,17,13] output set: {(3,4,5), (5,12,13), (8,15,17)} Try to minimize time complexity to O(n) if possible.
-
An array of size n+1 has integers only from 1 to n. The integers 1 to n can be present 0 or more times in the array. Find the first repeating element in the array. Restrictions: O(n) algo required. Cannot use extra space(not even O(1)).
-
Given a hierarchical structure i.e., you have a parent class, a child class which extends a parent class which has some attributes and methods. You need to parse the structure and output should give you the set of the base class, set of derived cl...
-
Write an algorithm to traverse a knight covering all the squares on a chessboard starting at a particular point
-
Given a list of n integers?(negative and positive), not sorted and duplicates allowed, you have to output the triplets which sum upto 0.
-
Count number of lines, characters and words in a file (Given that we dont have much access to flashy java methods like readline, String methods like indexOf etc.)
-
(0,0) to (N,N) grid is there. You can move up and right from (0,0) to (N,N). How many paths are there? i n ii n^2 iii. n! iv. (2n)!/ (n! n!)
-
Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a row-button toggles the values of all...
-
Consider product ratings of amazon. ( these are avg ratings out of 5, say 3 persons gave it rating of 3 4 and 5 ,the avg rating would be 4 ). For given large amount of products you have to find top ten products based on these avg ratings. No...
-
There are N people in a room and one of them is a celebrity. Everybody knows at least the celebrity while the celebrity knows no one. You enter the room to find the celebrity. You are only allowed to pick a person, point to another person, and ask...
-
Given a graph, write a program to find if it is a bipartte graph or not!!!
-
You have to develop a piece of code that can be attached to a program like Microsoft Word, which would list the last "N" words of the document in descending order of their occurrence, and update the list as the user types. What code would you writ...
-
Steps involved in insertion and deletion of a node from skip lists?
-
Given a set of overlapping intervals of the form (start, end), each of which is associated with a property (say S), print a sequence of disjoint intervals with all properties current valid in that interval. eg. (1, 3, S0) (2, 3, S1) (2, 4, S...
-
Find gcd of 2 numbers U & V in O(log UV)^2 .
-
Consider there are N players who have a round robin tournament. input is a data structure which says who won the match for every pair <i , j> i != j. write an algo to give a sequence A[1...n] such that for ever i , i th player lost to i+1 th...
-
Make a data structure which is supposed to log number of user requests per second. At any point of time your boss can ask you the number of hits for the last 60 seconds. It can be at any time for example he will say at 71st second that tell me how...
-
Generate prime Number in range of [a,b] , more concentrate on Time Complexity of Algorithm How its O(nlognlog(logn)) Can Anyone explain in detail ?
-
Code to see if a binary tree is a BST or not.
-
You are given a String number containing the digits of a phone number (the number of digits, n, can be any positive integer) . To help you memorize the number, you want to divide it into groups of contiguous digits. Each group must contain e...
-
Algorithm to partition a set of numbers into two such that diff bw their sum is min and they have equal number of elements
-
Many irregular shape objects are moving in random direction. provide data structure and algo to detect collision. Remember that objects are in million.
-
How does a spell checker routine (common to both, word and PowerPoint) use d? I mean is the code copied 2 times for each of the processes in the main memory, if they are different processes or how is it used if they are threads.
-
Every number ending in 3 has a multiple of the form "111...111"
-
Interviewer asked me to implement power function, I suggested a recursive implementation where we multiply x^y/2 and x^y/2 for calculating x^y. But asked me for an efficient iterative algorithm.
-
Design a temperature control system in your house.
-
Given an array of numbers from 1 to 100, the array has all numbers except two missing numbers. how to find the missing numbers? (no sorting and no hashing)
-
We have a file containing all product IDs. Write a code to retrieve all the Unique IDs that start with 'b' and doesn't have any special characters in it.
-
We have a collection of N distinct items. Now we arrange them in an order and mark there positions from 1 to N. Now we rearrange the items in some random order and again mark there positions from 1 to N. So we have two arrangments of N items. Now ...