kishore
BAN USER
Questions (4)
Comments (4)
Reputation 75
- 2of 2 votes
AnswersWrite a function which compress string AAACCCBBD to A3C3B2D
- kishore in United States| Report Duplicate | Flag | PURGE
Amazon Software Development Manager Algorithm - 0of 0 votes
AnswersExplain the output:
- kishore in United States
#include <stdio.h>
int main() {
int x = 1;
x=++x/x++;
printf("%d\n",x);
}| Report Duplicate | Flag | PURGE
C - -1of 1 vote
AnswersWhat would be the output of this program.
- kishore in India
#define colums 4
#define rows 3
main()
{
int i,j,k;
int a[rows][colums]={4,5,6,7,8,9,10,11,12};
i=j=k=99;
for(i=0;i<rows;i++)
for(j=0;j<colums;j++)
if(a[k][j]<k)
k=a[i][j];
printf("%d\n",k);
}| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
suppose we have an array a[]={55,77,11,43,66}
- kishore May 23, 2013what one is supposed to do is take each element, compare it with every other elements to its right.
why would you compare it with every other elements to its right?
First do it for 1st element, say x=a[0].
55<77
55>11
55>43
55<66
here two elements(77,66) are greater than 55 to its right.
55 is ith element
77 is (i+1)th element
66 is (i+5)th element
here you shouldn't stop after seeing very first element say y>x (77>55)
cause y may be the next greatest element in this particular array
but not in the number line.
but here we've 66 which is greater than 55 and nearest to it.
so you should printf 55 --> 66
same way it can be done for other elements
77 --> -1
11 --> 43
43 --> 66
66 --> -1
that's why time complexity is o(n^2).