Microsoft Interview Question for Software Engineer in Tests


Team: Server and tools in microsoft erp
Country: United States
Interview Type: In-Person




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

The O(n) solution is using Kadane's algorithm

- Anonymous April 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

int getMaxSum(int *arr, size_t len, size_t &start, size_t &end) {
    start = end = 0;

    size_t ti = 0;
    int sum = 0;
    int max_sum = 0;
    for(size_t i = 0; i < len; ++i) {
        sum += arr[i];
        if(max_sum < sum) {
            max_sum = sum;
            start = ti;
            end = i;
        } else if(sum < 0) {
            sum = 0;
            ti = i + 1;
        }
    }
    return max_sum;
}

- arc April 22, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Does it cover the case with all negative integer inputs? Anyway modification is easy: just keep track of the largest number in the input. That's the result.

- iman.goodarzi March 07, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

private void getBiggestSumSubset(int []arr){
		
		
		int sum = 0;
		int max =0;
		
		for (int i = 0; i < arr.length-1; i++) {
			
			
			for(int j=i+1;j<arr.length;j++){
				
				sum=0;
				for(int k=i;k<j;k++){
					
					sum = sum+arr[k];
					
					
				}
				
				if(sum>max){
					max=sum;
					
					System.out.println("i="+i+"=j="+j);
					System.out.println("arr[i]="+arr[i]+"=arr[j]="+arr[j]+"=max="+max);
					
				}
				
				
				
			}
			
		}

}

- suvrokroy May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private void getBiggestSumSubset(int []arr){
		
		
		int sum = 0;
		int max =0;
		
		for (int i = 0; i < arr.length-1; i++) {
			
			
			for(int j=i+1;j<arr.length;j++){
				
				sum=0;
				for(int k=i;k<j;k++){
					
					sum = sum+arr[k];
					
					
				}
				
				if(sum>max){
					max=sum;
					
					System.out.println("i="+i+"=j="+j);
					System.out.println("arr[i]="+arr[i]+"=arr[j]="+arr[j]+"=max="+max);
					
				}
				
				
				
			}
			
		}

}

- suvrokroy May 13, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>

int main()
{
  int *arr,n,sum=0,max=0,o_start,o_end,c_start=0,i;
  scanf("%d",&n);
  arr=malloc(n*sizeof(int));
  for(i=0;i<n;i++)
      scanf("%d",arr+i);
  for(i=0;i<n;i++)
  {
    if(arr[i]<0)
    {
       if(sum>max)
       {
          max=sum;
          o_start=c_start;
          o_end=i-1;
       }
    }
    if(sum+arr[i]<=0)
    {
       c_start=i+1;
       sum=0;
    }
    else
       sum=sum+arr[i];
  }
  if(c_start==i)
     printf("no +ve elements\n");
  else
  {
     if(sum>max)
     {
        o_start=c_start;
        o_end=i-1;
     }
     printf("start-->%d , end-->%d\n",o_start,o_end);
  }
}

- Anonymous May 24, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you please elaborate the question. :)

- Anonymous June 10, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

It could be the array itself. Start index is 0 and end index is arr.length - 1

- Anonymous June 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you elaborate the question..? With an Example Array?

- anonoymous September 17, 2012 | Flag Reply


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