yogi.rulzz
BAN USER
- 0of 0 votes
AnswerThere are two string pattern P and searching Expression Ex.. Ex is regular expression contains only # which stand for any character latest one length..
- yogi.rulzz in India
P:- ABABABA Ex:- A#B#A P and Ex are similar so its true.
example2. P: ABACBCB Ex:- A#B result:- true
Example:- P: ABCABCCE Ex:-A#C# result:- true, as P contains the expression as Ex
P: ABCABCCE Ex:-A#C false: P is doesnot contains the express like A#C
# --- means at least one or more character. In java language you have write the algorthim| Report Duplicate | Flag | PURGE
Akamai Development Support Engineer Algorithm - 0of 0 votes
AnswersThere are two string pattern P and searching Expression Ex..
- yogi.rulzz in India
Ex is regular expression contains only # which stand for any character latest one length..
P:- ABABABA
Ex:- A#B#A
P and Ex are similar so its true.
example2.
P: ABACBCB
Ex:- A#B
result:- true
Example:-
P: ABCABCCE
Ex:-A#C#
result:- true, as P contains the expression as Ex
P: ABCABCCE
Ex:-A#C
false: P is doesnot contains the express like A#C
#--- means at least one or more character.| Report Duplicate | Flag | PURGE
Akamai Development Support Engineer Algorithm - 0of 0 votes
AnswersThere are two string pattern P and searching Expression Ex..
- yogi.rulzz in India
Ex is regular expression contains only # which stand for any character latest one length..
P:- ABABABA
Ex:- A#B#A
P and Ex are similar so its true.
example2.
P: ABACBCB
Ex:- A#B
result:- true
Example:-
P: ABCABCCE
Ex:-A#C
false: P is doesnot contains the express like A#C
#--- means at least one or more character.| Report Duplicate | Flag | PURGE
Akamai Development Support Engineer Algorithm - 0of 0 votes
Answersyou have given a post-fix of a binary try in which either you have 0 child(leaf node) or 2 child(internal node).
- yogi.rulzz in India
one more condition that all internal node are denoted via "i" and leaf node via "l".
we have to create this binary tree with this posfix.| Report Duplicate | Flag | PURGE
Akamai SDE-2 Algorithm - 0of 0 votes
AnswersIn an interview I was asked a question on strings. The problem is given a string s1= "ABCDBCCDABCD". and a pattern "BC". we have to replace this pattern with other string ("UVW" or "U"or "uv"). Do this without creating new string.
- yogi.rulzz in United States
Take the case to replace "BC" with following
a) "uvw" s1=AUVWDUVWCDAUVWD .
b) "U" s1=AUDUCDAUD .
c) "UV" s1=AUVDUVCDAUVD .
This was my first question and I was stuck on this. :(| Report Duplicate | Flag | PURGE
Microsoft SDE1 Algorithm - 0of 0 votes
AnswersSuppose you have some guests arriving at a party. For each guest, you are given the arrival and departure time. When a guest arrives he is given a wine glass and when he leaves he returns that wine glass (it becomes available to be given to another guest). Find the minimum number of wine glasses needed to serve all the guests. The arrival and departure team can only be between 1800 to 2359 hours.
- yogi.rulzz in India| Report Duplicate | Flag | PURGE
Directi Developer Program Engineer Software Engineer / Developer Algorithm
1) Join()=> the current thread has to wait for the thread's object exit status.
2) wait()=> wait() tells the calling thread to give up the monitor and go to sleep until some other thread enters the same monitor and calls notify( ).
3) Sleep()=> it hold the current thread execution.
Wait() releases the lock() of the moniter
@Westake Could you please explain your terminalnogy.. its difficult for me to understand.
Please give solve a example for finding doublet.
It is already mentioned the sun array should be continuous...
- yogi.rulzz October 27, 2013int find_Max(Node *root){
int sum=0;
if (root==null)
return 0;
else
{
int left_sum=find_Max(root->left);
int right_sum=find_Max(root->right);
sum=max( left_sum,right_sum)+root->value;
return sum;
}
}
We are comparing the character of str2 with the str1. so increment the count on the character when encounter the character in str1 and decrement in str1.
if the length of the two string is different return false and if any of the element in the count array is non zero then return false .
bool areAnagram(char *str1, char *str2)
{
// Create two count arrays and initialize all values as 0
int count[NO_OF_CHARS] = {0};
int i;
for (i = 0; str1[i] && str2[i]; i++)
{
count[str1[i]]++;
count[str2[i]]--;
}
if (str1[i] || str2[i])
return false;
for (i = 0; i < NO_OF_CHARS; i++)
if (count[i])
return false;
return true;
}
complexity O(n).
space complexity : 265*sizeof(int)
Can you please give me test case for the below step...
d. If there are two nodes then 2 scenarios arise:
1. If the first element is larger than the other so as it is inorder traversal the first element becomes the root and the next one comes in the right subtree.
2. If the first element is smaller than the other so the other becomes the root and this element comes in the left subarray.
I think the complexity of the method is O(n). correct me if I m wrong.
- yogi.rulzz July 24, 2013Hi LinhHA05,
Please attach the standard link.
/*
You have two sorted list A and B.
A = [1, 3, 4, 6,8,10, 17, 34]
B = [2, 8, 17, 33, 44, 66, 89, 100, 123]
Write a program to print those numbers which are
1) in A and not in B
2) in B and not in A
Eg: After print: 1 , 3 , 4 , 6 , 10, 33, 34, 44,, 66, 89, 100, 123
*/
#include<iostream>
#include<vector>
using namespace std;
void printArray(int *a, int *b, int _a,int _b )
{
int i=0,j=0;
vector<int> onlyA;
vector<int> onlyB;
vector<int>::iterator it;
for(;i<_a && j<_b;)
{
if(a[i]==b[j])
{
i++;
j++;
}
else
if(a[i]<b[j])
{
if(a[i]!=a[i-1])
onlyA.push_back(a[i]);
i++;
}
else if(a[i]>b[j])
{
if(b[j]!=b[j-1])
onlyB.push_back(b[j]);
j++;
}
}
while(i<_a)
{
onlyA.push_back(a[i++]);
}
while(j<_b)
{
onlyB.push_back(b[j++]);
}
cout<<"Present in a only"<<endl;
for(it=onlyA.begin();it!=onlyA.end();++it)
cout<<*it<<endl;
cout<<"Present in b only"<<endl;
for(it=onlyB.begin();it!=onlyB.end();++it)
cout<<*it<<endl;
}
int main()
{
int a[]={1,2, 3, 4, 6,8,10, 17, 34} ;
int b[]={2,2,2,2, 8, 17, 33, 44, 66, 89, 100, 123};
printArray(a,b,sizeof(a)/sizeof(a[0]),sizeof(b)/sizeof(b[0]));
return 0;
}
/**
* count the no of nodes in the subtree rooted at root and containing n1 and n2.
*
*/
int countNodes(struct node* root)
{
int count=0;
if(!root)
return count;
else
{
count=countNode(root->left);
count=countNode(root->right);
count++;
}
return count;
}
int LCA(struct node* root, int n1, int n2)
{
if(root == NULL || root->data == n1 || root->data == n2)
return -1;
if((root->right != NULL) &&
(root->right->data == n1 || root->right->data == n2))
return root->data;
if((root->left != NULL) &&
(root->left->data == n1 || root->left->data == n2))
return root->data;
if(root->data > n1 && root->data < n2)
return countNodes(root->data);
if(root->data > n1 && root->data > n2)
return LCA(root->left, n1, n2);
if(root->data < n1 && root->data < n2)
return LCA(root->right, n1, n2);
}
- yogi.rulzz April 04, 2013#include<iostream>
#include<cmath>
#include<climits>
using namespace std;
int findRange(int p1,int p2, int p3)
{
return max(max(abs(p1-p2),abs(p2-p3)),abs(p3-p1));
}
int** findMin( int **p1,int **p2,int **p3)
{
int **m = p1;
if (**m > **p2) m = p2;
if (**m > **p3) return p3;
return m;
}
int main()
{
int a[]={4, 10, 15, 24, 26,-1};
int b[]={0, 9, 12, 20,-1};
int c[]={5, 18, 22, 30,-1};
int i=0;
int *p1=a,*p2=b,*p3=c;
int min=INT_MAX;
int **t;
while((*p1 != -1)&&(*p2!=-1)&&(*p3!=-1))
{
int(findRange(*p1,*p2,*p3)<min);
min=findRange(*p1,*p2,*p3);
t=findMin(&p1,&p2,&p3);
(*t)++;
}
(*t)--;
cout<<*p1<<"'"<<*p2<<"'"<<*p3<<"'"<<min<<endl;
return 0;
}
Can anyone please explain the question.. I didn't understand... or any other link relevant to this
- yogi.rulzz March 27, 2013This cannot a google interview question. This is basic rule of inheritance+ virtual function
if base class does not have virtual function ==-> function calling is based on type of pointer
and if the base class contain a virtual function then that function will be called on the base of content of the pointer.
So in this case the display is not virtual.. to the display of base class is called because you are accessing it via base class pointer.
try to run this code
#include <iostream>
using namespace std;
class Base {
public:
char* name;
virtual void display() {
cout << name << endl;
}
};
class Derived: public Base {
public:
char* name;
void display() {
cout << name << ", " << Base::name << endl;
}
};
int main() {
Derived d;
d.name = "Derived Class";
d.Base::name = "Base Class";
Derived* dptr = &d;
// standard conversion from Derived* to Base*
Base* bptr = dptr;
// call Base::display()
bptr->display();
}
in the code the display() drived class will be called as content of base pointer is a address of drived calls instance..that is the content of the pointer is a drived class.
- yogi.rulzz December 15, 2012every thing is clear except the the algo for finding the starting pt of the loop...please someone explain in clear way..
- yogi.rulzz May 26, 2012I have a question, Which is not related to this question... Which stucture is good to store infix notation.. if I you vector<char*> then we have overhead to scan the number(number can be double digit or single....) if i use vector<int> then we cannot store the operators.
- yogi.rulzz May 24, 2012One example is required
- yogi.rulzz December 17, 2011I have a doubt regarding trimming of BST.
the new trimmed tree should contain the node which are in the range of int A and B.
if the code is 50 and you A and B is 10 and 30... so we will not consider this node as it is not in the range of A and B.
can you please explain how it will lead toO(1) access
- yogi.rulzz April 21, 2015