## Rapleaf Interview Question for Software Engineer / Developers

• 0

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

What is the need of sorting the array for finding maximum number..
Its possible in O(n) only..
max=0;
REP(i,n)
{
if(arr[i]>max)
max=arr[i];
}
print max;

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

Merge Sort, the complexity is n(log n)

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

Idea you are right or Question itself is wrong.

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

I think the question is correct as well as "idea's" answer is correct. So essentially you would use Bubble sort approach for just one iteration. One iteration of merge sort approach wont give you the answer.

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

I agree, you would use Bubble sort (1 pass) which will bublble the max element at the last/first position and return that index. But what if the array size is > 1000?

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

Using one pass of bubble sort to find the maximum is just plain silly. Why would anyone want to do any swapping of elements?

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

Hi Tom i havn't understand what u are trying to say? Anyway it requires one full iteration o(n)

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

I'm not able to figure out why people are hell-bent on using some kinda sort techniques just to get the max of the list...just iterate over the list keeping track of the max seen so far...as mentioned by 'nav'...thats it...O(n) solution...no question of thinking about any sorting techniques...

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

the question was actually asked to test the understanding that in i th iteration in bubble sort we get i th maximum for sure.

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

the question is which among bubble sort and merge sort which one is better... its not the question of HOW to find max of array... well everyone knows the answer.

the second part of the question says if array length is more than 1000 ... some people still are doubtful its bubble sort or merge sort ....... may be this question is to sort those people out of the list of "possible candidates" :P, has anyone here replying here passed the test??

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

I think the answer is pretty straight forward, it would be bubble sort. Lets start with a simple thing, bubble sort takes o(n^2) time complexity but 0(1) space complexity where as merge sort takes O(nlogn) time and o(n) space complexity. Though bubble sort would take O(n^2) worst case, we will never experience that because we just have to find the maximum element hence whether array is < 1000 or more than 1000, bubble sort would be preferred. If you want the entire array to be sorted then merge sort is definitely a good solution but in case of maximum element, bubble sort is your best friend

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

John, you're right that bubble sort is what you'd choose (if you were trying to over-complicate it), but that's a long way from saying that bubble sort is your best friend. Want to find the max element? Do a linear scan for the largest element. Done. O(n). One loop.

This is nothing but an idiotic question designed to trip people up based on wording and their tendency to move quickly through questions on a timed test.

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.