Yahoo Interview Question for Software Engineer / Developers


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

- sj October 30, 2016 | Flag Reply
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 }
  }
}

- NoOne October 30, 2016 | Flag Reply
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).

- vishalsahunitt November 08, 2016 | Flag Reply
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;
}

- rsingh November 09, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.


Add a Comment
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.

Learn More

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.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More