Monday, September 20, 2010
How will you find whether a number is a proper square or not?
How will you find whether a number is a proper square or not?
sum of two linked list
Take a number 1234. It can be represented in the form of a linked list, where the head of the list points to the node having value 1, that one pointing to 2, that one to 3, and then 4.
Similarly 2 linked lists are given. Their digit count is known to you in advance. You need to add the 2 lists and create a new list without changing the existing list (reversing) or using recursion.
Similarly 2 linked lists are given. Their digit count is known to you in advance. You need to add the 2 lists and create a new list without changing the existing list (reversing) or using recursion.
Balanced bit array
You are given a bit array (i.e each element is 0 or 1) A[1..n].
A bit array is called balanced if the number of times 01 appears is same as the number of times 10 appears. By 01 appearing we mean that A[i] = 0 and A[i+1] = 1 for some i.
i.e.
S1 = { i : A[i] = 0 and A[i+1] = 1}
S2 = {j : A[j] = 1 and A[j+1] = 0}
The array is balanced if number of elements in S1 is same as number of elements in S2.
Eg: A = [1,0,1] is balanced.
A = [0,0,0,0,0,0] is balanced too.
Give an algortihm to determine if a bit array A[1...n] is balanced.
A bit array is called balanced if the number of times 01 appears is same as the number of times 10 appears. By 01 appearing we mean that A[i] = 0 and A[i+1] = 1 for some i.
i.e.
S1 = { i : A[i] = 0 and A[i+1] = 1}
S2 = {j : A[j] = 1 and A[j+1] = 0}
The array is balanced if number of elements in S1 is same as number of elements in S2.
Eg: A = [1,0,1] is balanced.
A = [0,0,0,0,0,0] is balanced too.
Give an algortihm to determine if a bit array A[1...n] is balanced.
shuttering subsequence problem
A and B are two strings of a finite alphabet. Let B^i be the string B concatenated i times to itself. E.g, if B = ab, then B^3 is ababab. The Stuttering Subsequence Problem is:
Given strings A and B, find the largest i such that B^i is a subsequence of A. Give an algorithm to solve the Stuttering Subsequence problem. Note, the problem asks for a subsequence check, and not a substring check.
Given strings A and B, find the largest i such that B^i is a subsequence of A. Give an algorithm to solve the Stuttering Subsequence problem. Note, the problem asks for a subsequence check, and not a substring check.
Data structure to store anagrams
What data structure you'll use as a dictionary to store the anagrams of a word.The idea was to store in a way to efficiently get and print all the anagrams.
Petrol bunk problem
There are n petrol bunks arranged in circle. Each bunk is separated from the rest by a certain distance. You choose some mode of travel which needs 1litre of petrol to cover 1km distance. You can't infinitely draw any amount of petrol from each bunk as each bunk has some limited petrol only. But you know that the sum of litres of petrol in all the bunks is equal to the distance to be covered.
ie let P1, P2, ... Pn be n bunks arranged circularly. d1 is distance between p1 and p2, d2 is distance between p2 and p3. dn is distance between pn and p1.Now find out the bunk from where the travel can be started such that your mode of travel never runs out of fuel.
ie let P1, P2, ... Pn be n bunks arranged circularly. d1 is distance between p1 and p2, d2 is distance between p2 and p3. dn is distance between pn and p1.Now find out the bunk from where the travel can be started such that your mode of travel never runs out of fuel.
Reach the end of array
Given an array of positive integers( including 0 ).
Each value in the array indicates how many jumps you can take to the right. So, e.g. if array[3] = 2, it means that position 4 & 5 are reachable from position 3.
Find out if the last element is reachable from the front
Each value in the array indicates how many jumps you can take to the right. So, e.g. if array[3] = 2, it means that position 4 & 5 are reachable from position 3.
Find out if the last element is reachable from the front
Subscribe to:
Posts (Atom)