Yahoo Interview Questions
 0of 0 votes
AnswersGiven that you can take one step or two steps forward from a given step. So find the total number of ways of
 gullu September 12, 2010
reaching Nth step. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersCount the number of set bits in a number. Now optimize for speed. Now optimize for size
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersAn array A[1....n] is said to have a majority element if more than half of its entries are the same.
 gullu September 12, 2010
Given an array, the task is to design an efficient algorithm to tell whether the array has a majority element,
and, if so, to find that element.
The elements of the array are not necessarily from some ordered domain like the integers, and so there can be
no comparisons of the form "is A[i] > A[j]?".
However you can answer questions of the form: "is A[i] = A[j]?" in constant time. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  1of 1 vote
AnswersYou are given with three sorted arrays (in ascending order), you are required to find a triplet
 gullu September 12, 2010
(one element from each array) such that difference between their positions is minimum Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersCalculate the Resistance in ohm's that a knights move would require on an infinite plane of resistors
 gullu September 12, 2010
of unit resistance. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven a set of coin denominators, find the minimum number of coins to give a certain amount of change.
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGet the width of a binary tree
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven a binary tree with the following constraints: a) A node has either both a left and right child
 gullu September 12, 2010
OR no children b) The right child of a node is either a leaf or NULL write code to invert this tree. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven the sequence S1 = {a,b,c,d,...,x,y,z,aa,ab,ac.... } and given that this sequence corresponds
 gullu September 12, 2010
(term for term) to the sequence S2 = {1,2,3,4,....} Write code to convert an element of S1 to the
corresponding element of S2. Write code to convert an element of S2 to the corresponding element of S1. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven N computers networked together, with each computer storing N integers, describe a procedure for
 gullu September 12, 2010
finding the median of all of the numbers. Assume that a computer can only hold O(N) integers
(i.e. no computer can store all N^2 integers). Also assume that there exists a computer on the network
without integers, that we can use to interface with the computers storing the integers. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersWrite a function that returns a node in a tree given two parameters: pointer to the root node and
 gullu September 12, 2010
the inorder traversal number of the node we want to return. The only information stored in the tree is
the number of children for each node Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersWrite a function to find the next prime number after a given number.
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersA man has two paper cubes on his desk. Every day he arranges both cubes so that the front faces show
 gullu September 12, 2010
the current day of the month. What numbers are required on the faces of the cubes to allow this for all
possible days in the calendar? Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Brain Teasers  0of 0 votes
AnswersA band is going in the street with a constant speed. Someone in the last row has a dog. The dog runs
 gullu September 12, 2010
ahead, reaches the front row of the band and gets back to it's owner. The dog's speed was constant all
the way and while it was running the band passed 50 feet. Find the length of the dog's path,if the
distance between the front and the rear row of the band is 50 feet. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Brain Teasers  1of 1 vote
AnswersThere are 100 doors in a row that are all initially closed. You make 100 passes by the doors starting
 gullu September 12, 2010
with the first door every time. The first time through you visit every door and toggle the door
(if the door is closed, you open it, if its open, you close it). The second time you only visit
every 2nd door (door #2, #4, #6). the third time, every 3rd door (door #3, #6, #9), etc, until you
only visit the 100th door. What is the state of each door after the last pass? Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Brain Teasers  0of 0 votes
AnswersAn apple is in the shape of a ball of radius 31 mm. A worm gets into the apple and digs a tunnel of
 gullu September 12, 2010
total length 61 mm, and then leaves the apple. (The tunnel need not be a straight line.) Prove that
one can cut the apple with a straight slice through the center so that one of the two halves is not rotten. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersYou have a machine which can do only multiply by 2, divide by 2 and
 gullu September 12, 2010
Addition of 2 numbers. Write a detailed algorithm to multiply any two
numbers, in this kind of a machine. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersWrite c++ working code for Given a large number with many digits, propose a method or data structure to
 gullu September 12, 2010
efficiently store them. Addition, subtraction, mult, division should be supported by your design. Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersLet f(k) = y where k is the yth number in the increasing sequence of nonnegative integers with the
 gullu September 12, 2010
same number of ones in its binary representation as y, e.g. f(0) = 1, f(1) = 1, f(2) = 2, f(3) = 1,
f(4) = 3, f(5) = 2, f(6) = 3 and so on. Given k >= 0, compute f(k). Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersCompute the discrete log of an unsigned integer.
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven a singly linked list, print out its contents in reverse order. Can you do it without using any extra space?
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  2of 2 votes
AnswersGiven a linked list with the following property node2 is left child of node1, if node2 < node1 else,
 gullu September 12, 2010
it is the right child.
O P


O A


O B


O C
How do you convert the above linked list to the form without disturbing the property. Write C code for that.
O P


O B
/ \
/ \
/ \
O ? O ?
determine where do A and C go Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersGiven a list of numbers ( fixed list) Now given any other list, how can you efficiently
 gullu September 12, 2010
find out if there is any element in the second list that is an element of the first list (fixed list). Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswerAn array of size k contains integers between 1 and n. You are given an additional scratch array of size n.
 gullu September 12, 2010
Compress the original array by removing duplicates in it. What if k << n? Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersSuppose you are getting an infinite binary stream of characters then after any point of time you need to
 gullu September 12, 2010
print whether the no is divisible by 3 or not, how will you do that? Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersAn array is of size N with integers between 0 and 1024(repetitions allowed). Another array of integers
 gullu September 12, 2010
is of size M with no constraints on the numbers. Find which elements of first array are present in the
second array. (If you are using extra memory, think of minimizing that still, using bitwise operators) Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm  0of 0 votes
AnswersHow many matches will be played in a knockout tournament between 9 teams get the general formula for n teams?
 gullu September 12, 2010 Report Duplicate  Flag  PURGE
Yahoo Software Engineer / Developer Algorithm
Open Chat in New Window