goelrinku90
BAN USER- 1of 3 votes
AnswersIs this code working fine ? if yes/no give reason ?
- goelrinku90 in India
#include<iostream>
using namespace std;
struct node
{
int a;
int b;
};
typedef struct node Node;
void swap(void *a,void *b)
{
void *temp;
temp=a;
a=b;
b=temp;
}
int main()
{
Node *a1,*b1;
a1=(Node*)malloc(sizeof(Node));
b1=(Node*)malloc(sizeof(Node));
a1->a=10;
a1->b=20;
b1->a=30;
b1->b=40;
cout<<a1->a<<" "<<a1->b<<endl;
cout<<b1->a<<" "<<b1->b<<endl;
swap(a1,b1);
cout<<a1->a<<" "<<a1->b<<endl;
cout<<b1->a<<" "<<b1->b;
}
I surprised to see the ans after compiling this code ... i think u enjoy this code... :)| Report Duplicate | Flag | PURGE
Microsoft Software Development Manager - 0of 0 votes
Answersfrom given array of n elements find the maximum element for each consecutive sub-array of k elements.
- goelrinku90 in India
eg.
array=[6,5,4,3,2,1]
k=3
ans=6 5 4 3
explanation:-
6 from array [6,5,4]
5 from array[5,4,3]| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Algorithm
- 1 Answer Amazon offer 6 month internshi...
Amazon offer 6 month internship to me but the other hand placement season is going in my college all the big company arrived at the college (like microsoft,oracle ,yahoo ,google etc but average package of my college is 6.5Laks)
- goelrinku90 April 01, 2013
so,either i go for internship or stay in college to being a part of placement season please reply| Flag | PURGE
if a[i] < a[i] + a[i-1] then
a[i] = a[i] + a[i-1] for all i>0 and then find maximum
time complexity = O(n)
and no extra memory required
question is easy they just want to know your pointer concepts you must know how many elements are present in the array ....code is
int main()
{
int arr[a][b][c][d][e];//any order does not matter
// and number of element in the array is a*b*c*d*e
invert(arr,a*b*c*d*e);
}
void invert(void *ptr,int count)
{
int* a=(int*)ptr;
for(int i=0;i<count;i++)
a[i]^=1;
}
this code done well because array elements are sorted in row order/column order :)
Hop u understand this
give solution better than n^2 log n
- goelrinku90 March 29, 2013its codechef question ....
- goelrinku90 March 27, 2013int minsum(node* root)
{
int ans,x,y;
x=y=infinity;
ans=root->data;
if(root->left)
{
x=minsum(root->left)
ans+=root->left->data;
}
if(root->right)
{
x=minsum(root->right)
ans+=root->right->data;
}
return min(x,y,ans);
}
nice solution thanks .... nitingupta :)
- goelrinku90 March 20, 2013please explain your code ....
- goelrinku90 March 19, 2013why size 3 please clear your solution ....
is 3 means size of k .... ?
we can create register variable instead of auto variable
like(register int i=0;i<128;i++)
it increase the performance
i m not sour but hopeful :)
first calculate depth of the tree and make tree complete with inserting nodes with zero values
and then apply breath first search and calculate sum of each level easily :)
use templates in c it will work
- goelrinku90 August 25, 2014