jayeshr007
BAN USER- 0of 0 votes
Answersrepresent a n-ary tree with a data structure.
- jayeshr007 in India for wafl
and also check whether tree has a cycle or not?| Report Duplicate | Flag | PURGE
NetApp Software Engineer / Developer Data Structures - 0of 0 votes
AnswersGiven a big string (str1) find (s1) and replace by (s2).
- jayeshr007 in India for NOSTG
Example :
str = "Hi i am abc and i am in abc"
s1 = "abc"
s2 = "pqrstuv"
So final o/p :
str1 = "Hi i am pqrstuv in pqrstuv"| Report Duplicate | Flag | PURGE
Cisco Systems Software Engineer / Developer C
Here is TC = O(n) solution
Have a Multiplier[] which keeps the multiplying factor
We have N denominations = {1,2,3,...,56} //here N=10
Given num = 189;
Algorithm :
for i=N-1 to 0
do
if num >= A[i]
{
Multiplier[N-i-1] = num/A[i] ;
num = A[i]*Multiplier[N-i-1] - num;
}
if num <= 0 then break;
}
So now Multiplier[] will have the factor by which the denominations to be multiplied and added up to get the reqd number.
189 = 3*56 + 1*21;
ohh i am so sorry its a typo!!..
final string shud be "Hi i am pqrstuv and i am in pqrstuv"
Since the matrix is sorted so is the submatrices.
- jayeshr007 December 05, 20121. compare key with A[m/2][n/2]
2. if key > A[m/2][n/2] , then search in the lower right submatrix
3. if key < A[m/2][n/2] , then search in the upper left submatrix
4. else if (key == A[m/2][n/2]) ret TRUE
5. else ret FALSE
recursively follow this
This gives a O(log(MN)) solution which is better than O(m)
Correct me if i am wrong