sanjay.2812
BAN USERchar *sumBinary(char *st1, char *st2)
{
char *str1, *str2, *str3;
int length,carry=0,res=0;
if(strlen(st1) > strlen(st2))
{
srt1=st1;
str2=st2;
str3=(char *) malloc (strlen(st1)+1);
}
else
{
srt1=st2;
str2=st1;
str3=(char *) malloc (strlen(st2)+1);
}
length1=strlen(str1);
length2=strlen(str2);
while (length2>=0)
{
res = (str1[length1] - '0') + (str2[length2] - '0') + carry;
str3[length1+1] = (char)((res % 2) + '0');
carry = res / 2;
length1--;
length2--;
}
while (length1>=0)
{
res = (str1[length1] - '0') + carry;
str3[length1+1] = (char)(res % 2 + '0');
carry = res / 2;
length1--;
}
str3[0]=(char)(carry + '0');
return str3;
}
getSum(int *arr, int NUM, int *numlist)
{
int temp=NUM;
for (int i=0,i<sizeof(arr); i++)
{
temp=temp-arr[i];
newlist=(int *) malloc ( sizeof(numlist)+sizeof(int));
newlist[0]=arr[i];
copy_arr(newlist,numlist);
if (temp>0)
{
getSum(arr,temp,newlist);
}
else if (temp <0)
{
return NULL;
}
else
{
print_arr(newlist);
}
temp=NUM;
free(newlist);
}
}
bool CheckBST(node *root)
{
Bool left,right;
if (root==NULL)
return (1);
if (root->right !=NULL && getLeft(root-right) < root->value)
return 0;
if (root->left !=NULL && getRight(root->left) > root->value)
return 0;
left=CheckBST(root->left);
right=CheckBST(root->right);
return (left && right);
}
int getLeft(node *root)
{
int val = root->value;
while (root->left!=NULL)
{
root= root->left;
val = root->value;
}
return val;
}
int getRight(node *root)
{
int val = root->value;
while (root->right!=NULL)
{
root= root->right;
val = root->value;
}
return val;
}
Answer to this question is Either sumof(N) -1 orr Sumof(N) depends if sum of initial A steps sumof(A) is Equal to K of not. If we can jump off the Kth step.
If not i.e. if we can't cross the kth step as it is broken..
So at max we can reach upto k-1 step
we can start subtracting k with the step starting from n then n-1 and so on. when the value is less then 0, Don't take that step and move to next.
Also see the below example.. to prove my point
1 2 3 4
{
2
/ \
1 3
\
4
2
/ \
1 4
/
3
3
/ \
2 4
/
1
3
/ \
1 4
\
2
}
- sanjay.2812 February 02, 2012whoever don't agree please put your comment for improvement..
I agree that there is only one possibility for complete binary tree that my expression is also giving ..there were not given that the array will make complete binary search tree.
I have given the solution on general level and it is correct. please provide me example to make it wrong. I will accept it...
but the examples I took.. my expression is satisfying ..
the answer is correct for completely balanced tree but not a tree which is not completely balanced.
In general I think the expression is
2^(int)((log n)+1) - n
for n=7 int(log7)+1=3
so 2^3-7=1 that is only one possibility.
@cooldaa thanks..
@eugrne : See by your self one tree is has 7 as root and other has 7 as leaf. how do you explain them as same??
what about below example..
example : 1 3 7 9 11 15
7
3 11
1 9 15
9
3 11
1 7 15
I think it may be 2^upper(ln(n))- n where n is the size of array
for example : 1 3 7 9 11 15
7
3 11
1 9 15
9
3 11
1 7 15
if most significant digit ae equal.. go for 2nd most significant digit.. and sord accourding to them.....
Or bring every element on the same scale... suppose 5 ans 51..
convert 5 to 50 abd keep track of it like we have multiplied it by 10..
sort it desc... revert the changes ...print the number..
think of below some senario also.. you need modification..
1. 5,51
2. 55,52
3. 55,557
4. 5571,5579
This is also my idea...
- sanjay.2812 December 11, 2011(m-2)*2 + (n-2)*2 +2
- sanjay.2812 December 06, 2011the worst case scenario will be O(n^2). you can use a array of same size as of number. or use int *
put the first at the base.
read the next element if greater then write the seq in the 2-D array replace the element of the first index be new number. else put the number in the second index. loop the same way until the last number.
print the 2-D array according to the row.
Best Case is O(N)
how its order on N^2 man... you can find min and max in the order of N ..
we need to handle also condition id no element in the matrix is setisfing the given condition.
9*8+8*9*9*9
- sanjay.2812 November 23, 2011use sufix tree... and for the collision use link list ..
- sanjay.2812 November 23, 2011why so much...
take 3 int variables.. count the occrence of each digit in the first parse of link list....
in the second parse replace the node value as the number of occrance of 1 then 2 and then 3....
take 3 int variables.. count the occrence of each digit in the first parse of link list....
in the second parse replace the node value as the number of occrance of 1 then 2 and then 3....
#include <stdio.h>
#include <conio.h>
int main ()
{
int a[6]; int ab,i=0;
char mac[]="aa:bb:cc:12:23:34";
char *aa=NULL;
char delims[] = ":";
getch();
ab= (int)strtok(mac,delims);
while (ab!=NULL)
{
printf(" %d %s ",ab,(char *)ab);
a[i]=ab;
i++;
ab= (int) strtok(NULL,delims);
}
getch();
}
structure can have employee details.. pointer to manager and array of pointer of employee reporting to him..
typedef struct employee{
employee detail;
struct employee *manager;
struct employee *repoter[];
}Employee;
use 6 pointers 2 for each number start and end of number sequence in array...
- sanjay.2812 September 23, 2011I am not telling he is right.. but you explanation is also wrong... in the given example 4 and 8 both is the part of array and 4 is factor of 8..
2 way I can explain..
go through number by number...
check num%p1==0 or num%p2==0 or num%p3==0
increase the counter upto k... our output is the last number...
2nd way is...
keep three variables associated with each prime number.. suppose i,j,k associated initialize with 1. 1 counter also
find min(p1*i,p2*j,p3*k)
increase the corresponding variable increase the counter by 1 until k. give the last number a output..
so what is the use of shorted array still the time complexity will O(n)
Use modified binary search... compare the middle element lay in which side of array..
my bad.. this is wrong..
- sanjay.2812 August 29, 2011we dont need to sort the n^2 pair's. simply sort the original array. and use the below logic.
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
product=a[i]*a[j];
the output will be already in sorted order.
I don't know how can you say this a incorrect. the solution is simple and straight forward. Number - (sum of 2 from ariginal array) exist in the 2nd array which is equal to the sum of two other number from original array. we have the 4 numbers in the original array.
think before commenting on someone.
Repha1904536, Android test engineer at ABC TECH SUPPORT
Hello, I am an Executive recruiter. My role is to fill executive, high-level positions at companies. I have been practicing ...
RepMiaDavis, abc at 8x8
I have excellent communication skills that allow me to effectively lead my team and convey my ideas to them so ...
Replleongardner, Animator at 247quickbookshelp
I am a writer and television producer living in the Corpus Christi area. I have always been fascinated by the ...
take one stack and one queue.
- sanjay.2812 June 09, 2015push root into stack..
while(!stack.empty() || !queue.empty())
{
while (!stack.empty())
{
elem=stack.pop();
print elem.value;
queue.push(elem->left);
queue.push(elem->right);
}
while(!queue.empty())
{
elem=queue.pop();
print elem;
stack.push(elem->left);
stack.push(elem->right);
}
}