Microsoft Interview Question for SDETs


Country: India
Interview Type: In-Person




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

nums = [1, 4, 5, 2, 3, 4, 5, 6]

for i in range(len(nums) - 2):
    print(max(nums[i], nums[i + 1], nums[i + 2]))

- Jay February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

nums = [1, 4, 5, 2, 3, 4, 5, 6]

for i in range(len(nums) - 2):
    print(max(nums[i], nums[i + 1], nums[i + 2]))

- Jay February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

nums = [1, 4, 5, 2, 3, 4, 5, 6]

    for i in range(len(nums) - 2):
        print(max(nums[i], nums[i + 1], nums[i + 2]))

- Jay February 18, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is there any requirements about time or space complexity?

- Anonymous February 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is there requirements about time or space complexity?

- vh.vahan February 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
#include<iostream>
using namespace std;

int maxElement(int *intArray, int size)
{
int maxValue = intArray[0];
for (int i = 0; i < size; i++)
{
if (maxValue < intArray[i])
maxValue = intArray[i];
}
return maxValue;
}

int main()
{
int intArray[] = { 1, 4, 5, 2, 3, 4, 5, 6 };
int size = sizeof(intArray) / sizeof(intArray[0]);
int *tempArray = (int *)malloc(size);

int i = 0, j = 0, count = 0;

for (int i = 0; i < size - 2; i++)
{
count = i;

for (int j = 0; j < 3; j++)
{
tempArray[j] = intArray[count++];
}

printf("Max value is - %d\n", maxElement(tempArray, 3));
}
}

- Basu February 19, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

We don't need to compare elements every time. Following is the solution with less number of comparisons.

import java.util.*;
import java.lang.*;
import java.io.*;

class Solution
{
	
	public static int findMaxIndex(int a[], int i){
		int maxIndex = i;
		if(a[maxIndex+1] > a[maxIndex]){
			maxIndex = maxIndex+1;
		}
		if(a[maxIndex+1] > a[maxIndex]){
			maxIndex = maxIndex+1;
		}
		return maxIndex;
	}
	
	public static void printNumbers(int a[]){
		int maxIndex = -1;
		
		for(int i = 0; i < a.length-2; i++){
			if(maxIndex == i-1){
				// find max again
			maxIndex = findMaxIndex(a,i);
			System.out.println(a[maxIndex]);
			}else{
				if(a[maxIndex] < a[i+2]){
					System.out.println(a[i+2]);
				}else{
					System.out.println(a[maxIndex]);
				}
			}
		}
		
	}
	public static void main (String[] args) throws java.lang.Exception
	{
		int a[] = {1,4,5,2,3,4,5,6};
		printNumbers(a);
	}
}

- Farji Coder April 02, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {

		int arr[] = { 1, 4, 5, 2, 3, 4, 5, 6 };
		int len = arr.length;
		int firstPair = 0;
		int secondPair = 0;
		int thirdPair = 0;
		int fourthPair = 0;
		int fifthPair = 0;

		for (int i = 0; i < len; i++) {

			if (i < 3) {				
				int big1 = 0;
				big1 = arr[i] > (arr[i + 1] > arr[i + 2] ? arr[i + 1] : arr[i + 2]) ? arr[i]
						: ((arr[i + 1] > arr[i + 2]) ? arr[i + 1] : arr[i + 2]);
				firstPair = big1;
			}

			if (i >= 2 && i < len - 3) {				
				int big2 = 0;
				big2 = arr[i] > (arr[i + 1] > arr[i + 2] ? arr[i + 1] : arr[i + 2]) ? arr[i]
						: ((arr[i + 1] > arr[i + 2]) ? arr[i + 1] : arr[i + 2]);
				secondPair = big2;				
			}

			if (i >= 3 && i < len - 2) {				
				int big3 = 0;
				big3 = arr[i] > (arr[i + 1] > arr[len - 3] ? arr[i + 1] : arr[len - 3]) ? arr[i]
						: ((arr[i + 1] > arr[len - 3]) ? arr[len - 3] : arr[len - 3]);
				thirdPair = big3;
			}

			if (i >= 4 && i < len - 1) {				
				int big4 = 0;
				big4 = arr[i] > (arr[i + 1] > arr[len - 2] ? arr[i + 1] : arr[len - 2]) ? arr[i]
						: ((arr[i + 1] > arr[len - 2]) ? arr[len - 2] : arr[len - 2]);
				fourthPair = big4;
			}

			if (i >= 5 && i < len) {
				int big5 = 0;
				System.out.print(arr[i] + " ");
				big5 = arr[i] > (arr[len - 2] > arr[len - 1] ? arr[len - 2] : arr[len - 1]) ? arr[i]
						: ((arr[len - 2] > arr[len - 1]) ? arr[len - 2] : arr[len - 1]);
				fifthPair = big5;
			}
		}

		System.out.println("Greatest from the First Pair - " + firstPair);
		System.out.println("Greatest from the Second Pair - " + secondPair);
		System.out.println("Greatest from the Third Pair - " + thirdPair);
		System.out.println("Greatest from the Fourth Pair - " + fourthPair);
		System.out.println("Greatest from the Fifth Pair - " + fifthPair);
	}

- Charankumar. H December 15, 2017 | 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