Given two strings s1, s2 check if s1 is a rotated version of s2 ?
Came across a neat solution via stackoverflow..
algorithm checkRotation(string s1, string s2)
if( len(s1) != len(s2))
return false
if( substring(s2,concat(s1,s1))
return true
return false
end
Monday, October 4, 2010
Tuesday, June 15, 2010
Numbers in a array..
Problem : You have a array of random numbers and you are given a number k. Find the 2 elements in the array which sum up to k.
e.g: If my array is {2,5,3,1,8,7,5,4} and k=6.Then 2 numbers that sum up to 6 are 5 and 1.
well, of course the complexity of alogrithm matters.. !!
e.g: If my array is {2,5,3,1,8,7,5,4} and k=6.Then 2 numbers that sum up to 6 are 5 and 1.
well, of course the complexity of alogrithm matters.. !!
Wednesday, June 9, 2010
Square Problem..
Consider a square X, Divide X into four equal pieces(four squares). Now remove one piece of the four pieces. You are left with a block formed by 3 small squares. How do you divide this block into four equal pieces of the same shape.
solution below..
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
and if you thought this was a solution, like I did, you are wrong - because these can not be considered shapes as they are not contiguous.. look down for the solution....
.
.
.
.
.
.
.
.
.
.
How to implement a queue using stack..
Assume the only data structure available for use is a stack. How would you implement a queue functionality using stack ?
hint : you can use multiple stacks..
solution : http://stackoverflow.com/questions/69192/using-stack-as-queue !
Note : on similar lines, it should be possible to implement a stack using queue..
hint : you can use multiple stacks..
solution : http://stackoverflow.com/questions/69192/using-stack-as-queue !
Note : on similar lines, it should be possible to implement a stack using queue..
Subscribe to:
Posts (Atom)