Software Engineer Interview Questions in Hyderabad, India | Glassdoor

# Software Engineer Interview Questions in Hyderabad, India

Software engineers write programs to design and develop computer software. Interviews are highly technical, so come ready to work through coding problems and math brainteasers. The specific questions you are asked will depend on what type of programming position you are looking for. Try researching a specific software discipline such as web development, application development, or system development.

## Top Interview Questions

Sort: RelevancePopular Date

Feb 29, 2012

Apr 1, 2010

### Software Development Engineer at Amazon was asked...

Sep 24, 2012
 Given an array of numbers, nums, return an array of numbers products, where products[i] is the product of all nums[j], j != i. Input : [1, 2, 3, 4, 5] Output: [(2*3*4*5), (1*3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)] = [120, 60, 40, 30, 24] You must do this in O(N) without using division.13 AnswersWell my answer was to divide the array in 2 different parts perform some logic and in end multiply both the arraysOne solution would probably be to go through entire array once, keep a track of total product, and then in another loop populate result array by setting each index as totalProduct / (value at index in argument array)oh.. but without division. Didn't see that part with my tiny browserShow More ResponsesIf you were not supposed to divide the array into two, for processing.... import java.util.*; class aNum2{ public static void main(String[] args){ int[] a= new int[5]; int[] b= new int[5]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; a[4]=5; int j; for(j=0;j<5;j++){ int i; int p=1; for(i=0; i<5; i++){ p=a[i]*p; } b[j]=p/j; } System.out.println(Arrays.toString(b)); } }if you werent supposed to use the division operator : import java.util.*; class aNum{ public static void main(String[] args){ int[] a= new int[5]; int[] b= new int[5]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; a[4]=5; int j; for(j=0;j<5;j++){ int i; int p=1; for(i=0; iPlease ignore the very first response .. there is a correction on line 20 If you were not supposed to divide the array into two, for processing.... import java.util.*; class aNum2{ public static void main(String[] args){ int[] a= new int[5]; int[] b= new int[5]; a[0]=1; a[1]=2; a[2]=3; a[3]=4; a[4]=5; int j; for(j=0;j<5;j++){ int i; int p=1; for(i=0; i<5; i++){ p=a[i]*p; } b[j]=p/a[j]; } System.out.println(Arrays.toString(b)); } }trick is to construct the arrays (in the case for 4 elements) for example { 1, a[0], a[0]*a[1], a[0]*a[1]*a[2], } // productsBelow { a[1]*a[2]*a[3], a[2]*a[3], a[3], 1, } // productsAbove then multiply productsBelow and productsAbove http://stackoverflow.com/questions/2680548/interview-q-given-an-array-of-numbers-return-array-of-products-of-all-other-nu#include using namespace std; int main(){ int a[4] = {1,2,3,4}; int b[4] = {1,1,1,1}; for(int i = 1 ; i =0; i--){ prod *= a[i+1]; b[i] *= prod; } for(int i = 0; i < 4; i++){ cout << b[i] << " " << endl; } }public class Example2 { static int[] Numarray={1,2,3,4,5}; public static void main(String[] args) { ArrayList arr1=new ArrayList(); int first=0; int count=1; for(int j=0;j<=Numarray.length-1;j++) { for(int i=0;iThere should be no divsion of array not even numbers so the solution goes like this //SIMPLIFIED APPROACH class amazon2 { public static void main(String rags[]) { int []a={1,2,3,4,5};//any digits as per approach int []b=new int[10]; int []c=new int[10];//dummy integer array for(int i=0;ipublic void printProduct(int[] a) { int[] b= new int[a.length]; for(int j=0;jpublic void printProduct(int[] a) { int[] b= new int[a.length]; for(int j=0;jprodSum = function (arr, memo, index) { if(index >= arr.length){ return; } for(var i=0; i

### Software Development Engineer at Microsoft was asked...

Jul 12, 2013
 out of 25 horses select the fastest three in minimum number of races where in each race there would be exactly five horses.10 Answers6 races i thinkit could be 6 races... first five races taking 5 horses each,and then the 6th ace taking the 1st horse of each of the previous race,den select the fastest three among them.would be 5 races if a stop watch is given..... however solutions given before are wrong since the horse coming 2nd in the first race might be faster than the horses that come first in the subsequent race :) hence we have to assume that a timer is providedShow More Responsesumesh no timer has been provided and it would be 7 races :)11 races First 5 races taking 5 horses in each race. Next 5 races taking in each race horses which have come first, horses which have come second, third, fourth and fifth....... Final 11th race out of 5 which have won in second set of races to find fastest 36 Race would be wrong answer. What if in one group all the 5 horses are fastest of all others. Then from first round of 5 races we might lose those 2nd and 3rd ones. My answer is also 11 Races.Round one - 5 Races -------------------- Including all 25 horses. 5 each race. Left with -> 15 horses [Take 1st,2nd & 3rd from each race. Which would be total of 5*3=15 horses.] Round two - 3 Races [ Grouping any 5 of 15 horses left] ------------------- Left with -> 9 horses [Take 1st,2nd & 3rd from each race. which would be total of 3*3=9 horses.] Round three - 1 Race. ---------------- Take any 5 horses of 9 horses left Left with -> 7 horses 3 (1st 2nd and 3rd) + 4 (remaining ones) = 7 horses Round four - 1 Race. ---------------- Take any 5 out of 7 Left with -> 5 Round Five - 1 Race ---------- Race of 5 horses left7 races: Split the 25 into 5 groups and make them race, this would be 5 races. Take the fastest horse of each group and make them race (6th race). Let's label the initial group of the top 3 horses of the 6th as a, b, c. The possible candidate for the 3 fastest are: a[1], a[2], a[3], b[1], b[2], c[1] We just need one last race to determine the top, the race would be between a[2], a[3], b[1], b[2], c[1]. The final result is a[1] then the top 2 of the 7th race.Easy: Correct answer is 11 but much easier method: 1. One race among 5 horses to find the fastest 3. 20 horses left not raced yet. 2. Now keep the 3 fastest horses you found and add two other horses out of 20 horses left to the race, again select the fastest 3. 3. Keep doing this for all 20 horses by selecting 2 of the horses left to race against the fastest 3 always. 1 race (to find the fastest 3) + 10 races (20/2 races to test all other 20 horses) = 11 racesConstant Time - 7 Races 5 Races among 5 each. 6th Race for all third place holders 7th Race for Winner of sixth race +two people who defeated him in 1st race + two people who defeated the second place winner in 6th race. Best Case - 6 Races (3 place winner of 1st race against other 20 and he wins all the time) Worst Case - 11 Races( Make the fastest 3 of each race run against the other 2 each time)

### Senior Software Engineer at Amazon was asked...

Oct 13, 2012
 You are given a fixed number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps. Now given an amount for sending a parcel, you should design an algorithm to come out with the minimum number of stamps that should be used for attaining that amount. For example, if the parcel costed 30 rupees, it could be attained using one 20 rupee stamp and one 10 rupee stamp OR using three 10 rupee stamps OR using one 20 rupee stamp and two 5 rupee stamps OR using one 10 rupee stamp and four 5 rupee stamps OR using two 10 rupee stamps and two 5 rupee stamps. However, the minimum number of stamps is the case of one 20 rupee stamp and one 10 rupee stamp where only two stamps are used. The case where no solution is possible should also be handled, for example, a parcel amount of exactly 33 rupees cannot be attained.9 AnswersThe solution is attained using dynamic programming. The basic idea is that the minimum number of stamps used for attaining an amount x, is 1+minimum of (minimum number of stamps for attaining x-5, minimum number of stamps for attaining x-10, minimum number of stamps for attaining x-20,minimum number of stamps for attaining x-50). You can try to solve this first by assuming that an unlimited number of 5 rupee, 10 rupee, 20 rupee and 50 rupee stamps are available. And then you can take into account that only a fixed number of these stamps are available.And what is the time involved to get this done? I really liked the question.Simple to read but involves good amount of logic. I ve written down the algorithm but i believe i took more time than i initially thought i would take.I understand what the interviewer is trying to test and I know how to solve it, but what about more realistic scenario where parcel postage cost would be beyond given values like 3 units of currency or 37 units of currency.Show More ResponsesIn this specific case, dynamic programming is overkill. There's a better optimal substructure here: The stamp with greatest value less than parcel cost minus stamp values already committed minimize the total of stamps.1. find the stamp <= cost from highest stamp cost 2. num of found_stamp = found_stamp/cost, rem_stamp = found_stamp % cost 3. Do 1, then 2 until rem_stamp ==0 (done) or rem_stamp < least stamp available (not possible case)In the previous ans, after step 3 if rem_stamp !=0, go back to step 1, find next_stamp < cost (but smaller than value of found_stamp in previous iteration)i=0; boolean solPossible = false; do { if(cost % notes[i] == 0) solPossible = true; else i++; } while(!solPossible && (ivoid sendParsal(int cost) { int[] avlstm={50,20,10,5}; int i=0; while(cost>=5) { while(cost>=avlstm[i]) { System.out.println(avlstm[i]); cost=cost-avlstm[i]; } i++; } if(cost!=0) { System.out.println("Solution not possible."); } }void Foo(int cost) { if (cost % 5 != 0) Console.WriteLine("Not possible"); else if (cost stampCosts = new List() { 50, 20, 10, 5 }; int count = 0; while (cost > 0) foreach (int stampCost in stamptCosts) if (cost >= stampCpst) { cost -= stampCost; Console.WriteLine("Stamp: " + stampCost); count++; break; } } Console.WriteLine("Count: " + count); }

### Senior Software Engineer at Virtusa was asked...

Sep 19, 2010
 if there are 6 people in a team, how many handshakes will be there8 Answers15There will be 30 hand shakes. In total we have 6 people, so it will be 6 * (6-1) (i.e 1 person will shake hands with 5 people)15 A | B | C| D | E | F | A will perform 5 B will perform 4 C will perform 3 D will perform 2 E will perform 1 F ultimately hand shakes with everyoneShow More Responses6c2==6!/(2!*4!)=15lets consider A,B,c,d,e,f so a shakes hand with the other 5 ..b with oter 4 and so on so at last 5+4+3+2+1=1515 people handshakes at a time you have given 6 person first of all the peoples is arranged in row 6 number people have an 5 option for handshakes after that 6 number person out then total number of people 5 again....again....same procedure apply.......Each one will shake hand 5 times, 6x5 -> 30 times6c2= 15

### Software Development Engineer In Test (SDET) at Microsoft was asked...

May 26, 2013
 Consider a stack of N number of cards which are piled up and in facing down. Each card has a unique number from the range 1 to N. The card is stacked in such a way that it exhibits the following behavior: Take the first card and put it under the stack without revealing. Now the next card on the top will have the number 1 on it. Next take 2 cards one after the other and put is under the stack without revealing. Yes you guessed it right - the next card on the top will reveal a value of 2. This goes on. Eg. for such a series : 9,1,8,5,2,4,7,6,3,10 [for N=10] Write a program to generate such a series for a given N number of cards so that this behavior can be exercised.8 AnswersPossible implementation in C++ -------------------------------------------------- int CounterStep(int counter,int N); int LocatePosition(int *cards,int N, int startPointer,int value); using namespace std; void main() { int cards[20]; int N=20; int POS = 0,TOP = 0; // Initializing everything to zero for(int i=0;iWritten in Python although it can be re-written in C/C++ if required. def generateSpecialSeries(numberOfCards): specialSeries = [] if numberOfCards > 0: for i in range(numberOfCards, 0, -1): specialSeries.append(i) currentSpecialElement = 1 currentIndex = 1 while currentIndex < numberOfCards: indexOfCurrentSpecialElement = numberOfCards - currentSpecialElement specialSeries[currentIndex], specialSeries[indexOfCurrentSpecialElement] = specialSeries[indexOfCurrentSpecialElement], specialSeries[currentIndex] currentSpecialElement += 1 currentIndex += currentSpecialElement + 1 return specialSeries specialSeries = generateSpecialSeries(50) print specialSeries specialElement = 1 specialElementSum = 1 currentIndex = 1 while currentIndex < 50: print specialSeries[currentIndex] == specialElement specialElement += 1 specialElementSum += specialElement currentIndex += specialElement + 1// Short and simple C++ algorithm #define N 10 void compute(int stack[]) // Make sure N elements are allocated { int j=0; for(int i=0; iShow More Responses#include using namespace std; int main(int argc,char **argv){ int count=20; int array[20]; for(int i=0;i>a; return 0; }Java implementation public class App { public static void main(String[] args) { String arr[] = new String[10]; int pointer = 0; for (int valueToPlace = 1; valueToPlace <= arr.length; valueToPlace++) { for (int x = 1; x <= valueToPlace; x++) { if (pointer == arr.length - 1) pointer = 0; else pointer++; if (arr[pointer] != null) x--; } System.out.println("Placing " + valueToPlace + " at index " + pointer); arr[pointer] = valueToPlace + ""; while (arr[pointer] != null && valueToPlace != arr.length) { if (pointer == arr.length - 1) pointer = 0; else pointer++; } } for (String str : arr) { System.out.print(str + ", "); } } }The algorithm used is: For each number n (ranging from 1 to 10), we have to skip n places in the array. And then put number n at that position. The catch in the program is that we can skip only, not occupied places (the array places where value is 0 by default). Also, when we reach the end of the array, we have to move back to beginning of array (similar to cards being kept at the bottom of the pile of cards.) Here, a variable 'pos' is used to store the final position of any element. Initially, pos is at 0. The skip() takes the array, the current value of pos and the number of skips to be made. For example, for n=1, the values passed to skip() would be: pos=0, n=1. This means that we have to skip 1 place starting from index 0. Similarly, for n=2, pos=1. This means we have to skip 2 places starting from index 1. Java Implementation: public class StackOfCards { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int[] arr = new int[10]; int pos=0; for(int n=1;n0){ if(arr[pos]==0){ //reduce the number of skips to be made n--; } pos++; //if end of array is reached, take pos back to beginning if(pos==10){ pos=0; } } // keep incrementing pos until a not occupied index is reached. while(arr[pos]!=0){ pos++; } return pos; } }Here is C# Code... namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int n = 36; int[] series = new int[n]; int LargestNumber = n; int SmallestNumber = 1, temp = 1, i; bool putLargeNumber = true; for (i= 0; i 0)) { series[i] = LargestNumber; Console.Write("{0} ", series[i]); LargestNumber = LargestNumber - 1; putLargeNumber = false; temp--; } else { series[i] = SmallestNumber; Console.Write("{0} ", series[i]); SmallestNumber += 1; putLargeNumber = true; temp = SmallestNumber; } } } } }import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; import java.util.Stack; public class MSQuestion1 { static int counter =1; public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int n =in.nextInt(); // x 1 x1 x2 2 x3 x4 x5 3 x6 int[] arr = new int[n]; int f = 0; while(f0)) { arr[f]=counter; counter++; } f++; } for(int i=0;i

### Software Development Engineer at Amazon was asked...

Apr 21, 2012
 Write code to count the number of bytes used for the int data type.4 Answersint CountIntBitsF() { int x = sizeof(int) / 8; return x; }^^ Your answer is incorrect. Look closely at the question.int *p; int count=(char *)(p+1) - (char *)(p);Show More Responsesvoid count_bytes_used() { int a = 66000, bytes=0; while (a > 0) { bytes++; a = a >> 8; } printf("BYTES USED: %d\n", bytes); }

### Software Development Engineer at Microsoft was asked...

May 26, 2012
 Find count of unique characters in a given string4 AnswersWhat kind of characters in the string? Assuming ASCII characters, total 256. Array should be a good choose. int uniqueCount(string str){ if(str.size()<2) return str.size(); int charNum[256]={0}; // initialized to zero //counting concurrency for(int i=0; ihere are two ways of attacking this: (1) sort the chars, then walk the list incrementing a count any time you hit a different char (2) take advantage of the fact that there are at most 256 ASCII characters, with values 0 to 255, so build a 256 sized array to hold all possible chars, then as you walk the list, increment the corresponding array entry holding a matching char. first approach: /* sort the string */ for (int i=0; ipublic void counter(String g) { int count; for (int i = 'a' ; i<='z' ; i++){ count = 0; for (int a = 0; aShow More ResponsesUsing single iteration :) ..... int map[256]={0}; //initialise map to 0 int count=0; string a="abcabnaabcabaccacbbbqf"; for(int i=0;i

### Software Development Engineer at Amazon was asked...

Jul 26, 2010
 Write production quality code to find whether a given binary tree is a BST or not. You can't make any global variable.3 AnswersA BST rooted at node N is defined such that all nodes to the left of N are less or equal to N, and all nodes to the right of N are greater or equal to N. And the left and right subtrees are BST as well. boolean isBST(Node N) { if (N == null) return true; Node L = N.left; Node R = N.right; boolean LV = L != null ? L.value = N.value : true; return LV && RV && isBST(N.left) && isBST(N.right); }left of N are less or equal to N, and all nodes to the right of N are greater or equal to N - clearly something is wrong here..........it can be either not both (strict inequality for atleast either of the side)this blog has a nice O(n) C code.. http://justprogrammng.blogspot.com/2012/06/check-if-tree-is-bst-on-code-interview.html
110 of 4,578 Interview Questions