Yahoo Interview Question for Software Engineer / Developers

• 0

Country: United States
Interview Type: Phone Interview

Comment hidden because of low score. Click to expand.
1
of 1 vote

two solutions: (1) using brute force check having time complexity O(n2)

``````int[] input={2,7,5,3,0,8,1};
int[] output=new int[input.length];
for(int i=0;i<input.length;i++)
{
int count=0;
for(int j=i+1;j<input.length;j++)
{
if(input[j]>input[i])
{
count++;
}
}
output[i]=count;
}

for (int i = 0; i < output.length; i++) {
System.out.print(output[i]+",");

}``````

2. add elements two a binary search tree and count number of elements in each node
complexity will be nlogn

Comment hidden because of low score. Click to expand.
1
of 1 vote

``````// ZoomBA
def surpasser_count( arr ){
len = #|arr|
list( [0:len] ) -> {
n = arr[ \$.item ]
sum( [\$.item + 1 : len] ) -> { arr[ \$.item ] > n ? 1 : 0 }
}
}``````

Comment hidden because of low score. Click to expand.
0
of 0 vote

Maintain a sorted array while traversing elements from right to left. Find what index the new element will be inserted at using binary search. Number of elements right to it is prepended into answer. The overall space complexity: O(n), time: O(nlogn).

Comment hidden because of low score. Click to expand.
0
of 0 vote

``````int printNewArray(int *arr,int size)
{
int *temp = new int(size);
int i;
for(i=0;i<size;i++)
{
temp[i] = 0;
}
for(i=size-1;i>=0;i--)
{
int j = size-1;
while(j>i)
{
if(arr[j]>arr[i])
{
temp[i] = temp[i]+1;
}
j--;
}
}
for(i=0;i<size;i++)
{
cout<<temp[i]<<" ";
}
cout<<endl;
return 0;
}``````

Comment hidden because of low score. Click to expand.

Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.