Mukesh Kumar Dhaker
BAN USERStep 1:sort L! in increasing order and L2 decreasing order.
Step2:-strat pointer from L1 is i and and L2 is j
where m is smallest arrey length;
while(j<m)
{
if(a[i]+b[j]==sum)
{ cout<<a[i]<<b[j]<<endl;i++;j++;}
else
{ if(a[i]+b[j]>sum) j++;
else
i++;
}
}
our program time complexity is O(nlog n);
bool findword(char a[][],char b[],int n,int m)
{ int count=b.length();
int k=0,t,p;
for(int i=0;i<m;i++)
for(int j=0;j<n;j++)
{ t=i;p=j;
if(a[t][p]==b[k])
{ if(a[t][p+1]==b[k+1]&&p<n-1) { p=p+1;k++;}
if(a[t][p-1]==b[k+1]&&p>=0) { p=p-1;k++;}
if(a[t+1][p]==b[k+1]&&t<m-1){ t=t+1;k++;}
if(a[t+1][p+1]==b[k+1]&&t<m-1&&p<n-1) { t=t+1;p=p+1;k++;}
}
else
{ if(count==k) retrun true;
else
k=0;
}
}
Step1:-use binary search for find where the second sorted arrrey start assume it is kth position then
Step2:-merge both arreys one is start from 0 to k-1 and second one start from k to n;
so our solution will take less time as it take for merging..!!
int maxprofit(int a[],int n)
{ int profit=0;
int min=a[0],max=a[0];
for(int i=0;i<n;i++)
{ if(a[i]<min) min=a[i];
if(a[i]>a[i+1])
{ profit+=a[i]-min; min=a[i+1];}
}
return profit;
}
void printsubset(int*arr,int*aux,int start,int depth,int n)
{ if(start<=n)
{ for(int i=0;i<depth;i++)
cout<<aux[i]<<" ";
cout<<"\n";
}
for(int j=start;j<=n;j++)
{ aux[depth]=arr[j];
printsubset(arr,aux,start+1,depth+1,n);
start++;
}
}
i think ans . is 8..
step1:if don't use 2 steps .then only 1 way
step 2: if we use single 2 steps ..then 4 ways
step 3: if we use double 2 steps .then 3 ways
so total combintaion is 8..
plz comment if you are not agreed!!
Step1: traverse postorder ex:8,2,5,25,19,21,15,17,29,20,10,40,50,30,9
Step2: traverse preorder ex:9,10,15,5,8,2,21,25,19,20,17,29,30,40,50
Step 3: if our two node 8 and 19 then in postorder the element after 19 ...21,15,17,29,20,10,40,50,30,9 and the elemnet before 8 in preorder 9,10,15,5
step 4: find the commen element in both ex. 9,10,15
Step 5: find the min in this arrey ex. from 9,10,15 is 9 so lowest commen ancester is 9.
Ex our tree is 9
10 / \30
15 / \ 20 40/ \ 50
5/ \ 21 17 / \29
8/ \2 25/ \19
void printsubset(int a[],int n)
{ for(int i=0;i<n;i++) cout<<a[i]<<" ";
cout<<"\n";
}
void printallsubset(int arr[],int tmp[],int asize,int tsize,int sum,int ite,int targetsum)
{
if(sum==targetsum) {
printsubset(tmp,tsize);
printallsubset(arr,tmp,asize,tsize-1,sum-arr[ite],ite+1,targetsum);
return;
}
else
{ for(int i=ite,i<asize,i++)
{ tmp[tsize]=arr[i];
printallsubset(arr,tmp,asize,tsize+1,sum+arr[i],i+1,targetsum);
}
}
}
int multiply(int a,int b)
{
while(b!=0)
{ if(b&1)
{ result=result+a;}
a=a<<1;
b=b>>1;
}
return result;
}
find Top to Bottom and left to right traverse in one tree....
and Top to Bottom and right to left traverse in another tree...
if both are same then tree have mirror image ....!!
#include<iostream>
using namespace std;
int fact(int n)
{ int fct=1;
for(int i=n;i>=1;i--)
{ fct=fct*i;}
return fct;
}
int main()
{ int x,m=1000000,p=401,count=0;
int i=1;
while(p<m)
{ p=401*i;
count++;
i++;
}
p=p-401;
x=m-p;
cout<<"the number of value x "<<x<<endl;
int a=fact(m);
cout<<count<<endl;
system("pause");
return 0;
}
#include<iostream>
#include<cstring>
using namespace std;
int main()
{ int n,max=0;
char s[30];
cout<<"enter the string\n";
for(int i=0;i<20;i++)
cin>>s[i];
for(int i=0;i<20;i++)
{ int count=0,max1=0;
for( int j=i,m=19;j<=m;)
{ if(s[j]==s[m])
{count++;j++;m--;
if(max1<count)
max1=count;
}
else
{ break;}
}
if(max<max1)
max=max1;
}
cout<<"max of palindrome length is"<<max<<"\n";
system("pause");
return 0;
}
i think this will gives the answer..
#include<iostream>
using namespace std;
int fact(int n)
{ int fct=1;
for(int i=n;i>=1;i--)
{ fct=fct*i;}
return fct;
}
int main()
{ int x,m=1000000,p=401;
int i=1;
while(p<m)
{ p=401*i;
i++;
}
p=p-401;
x=m-p;
cout<<"the number of value x "<<x<<endl;
int a=fact(m);
int b=fact(x);
int c=fact(m-x);
b=b*c;
int y=a%b;
cout<<y<<endl;
system("pause");
return 0;
}
Suppose your i/p is :- my name is dhaker i am from warangal my branch is computer science and enggineering i want placement in adobe.
- Mukesh Kumar Dhaker March 14, 2013for all count[]=0;
char *ch=strtok(str," ");
hash(ch);
while(ch)
{ ch=strtok(ch," ");
hash(ch);
}
for(int i=0;i<10;i++)
{
for(int j=0;j<n-i;i++)
{ if(count[i]>count[j])
swap(count[i],count[j]);
}
cout<<count[9-i]<<" ";
}
void hash(char*c)
{ for(int i=0; ;i++)
{ if(strcmp(c,s[i])==0) count[i]++;
else
{ strcpy(s[i],c); count[i]++;}
}
}