Software Interview Questions | Glassdoor.co.in

# Software Interview Questions

65,573

Software interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

23 Apr 2010

29 Feb 2012

### Software DesignEngineer In Test (SDET) at Amazon was asked...

20 Feb 2011
 Given a number find it is one less than the power of two. 15 AnswersThe question could have been a little more detailed, most of the guys who took up the test could not understand this immediately.Given a number N, XOR it with N+1 = powers of 2 will give all 0s@Anonymous. That's not true. 3 in binary is 11 and 4 is 100, if you XOR 011 and 100 you will get 111, not 000. I think you meant to say that all numbers will be 1s.Show more responsesN xor (N+1) = 2*N + 1If the least bit is 1, then it is equal to N less than power of 2 if ( n << 7 ) cout << "It is one less than power of 2" For example 1 - 0000 0001 3 - 0000 0011 5 - 0000 0101 7- 0000 0111// the power of two is always has the first bit set to1 and rest all would be set to 0. And one less than power of 2 has all the bits set to 1 except the fist bit. for example 16 = 10000 and 15 = 01111 Now if you do bit operation & on 16 and 15, you get zero. Hence, below is the code. public boolean oneLessPowTwo(int num){ boolean b = false; if(n & n+1 == 0){ b = true; } return b; }the power of two is always has the first bit set to1 and rest all would be set to 0. And one less than power of 2 has all the bits set to 1 except the fist bit. for example 16 = 10000 and 15 = 01111 Now if you do bit operation & on 16 and 15, you get zero. Hence, below is the code. public boolean oneLessPowTwo(int num){ boolean b = false; if((num & (num+1)) == 0){ b = true; } return b; }A one line answer to this question is: -1 + 2 to the power of -2 - language binary string prefix + length of binary string for N In Python: 2**(len(bin(511))-3)-1 Simple one line in any language with a function to convert int to binary string.8 anwerJust another option of doing this Boolean checkNumber(int inputNum) { int temp = 2 ; while(temp < inputNum) { temp = temp * 2 ; } if(inputNum == temp-1) return True; else return False; }can any1 say it clarly..wt is dz 15+01111??can any 1 say it clearly?package amazonExcerise; import java.util.Arrays; import org.apache.jasper.tagplugins.jstl.core.ForEach; public class concatenationArrays { public static void main(String[] args) { int a[] = { 1, 3, 77, 78, 90 }; int b[] = { 2, 5, 79, 81 }; int c[] = new int[9]; int j = 0; for (int i = 0; i 4) { c[i] = b[j]; j++; } System.out.print(" " + c[i]); } Arrays.sort(c); System.out.println(""); System.out.println("Sorted Array"); for (int i : c) { System.out.print(" "+i); } j = 0; System.out.println(); System.out.println("Array A:"); j = 0; for (int i = 0; i = 5) { b[j] = c[i]; System.out.print(" "+b[j]); j++; } } } }Show more responsesFor a number n, if n <= 1 the question doesn't really make sense. You can approach custom essay writing services for getting more details for your academic works.Visit http://essayguardian.com/.N is the number so (1<

1 Apr 2010

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

11 Oct 2012
 Why do you want to join Wipro ? and please don't give me crap answers !12 AnswersDon't say, this is the best company and all the regular stuffIts just for the fame,good salary,n happy life as i heard it s one of the best company too......:-)because, its good company and attractive salary,...Show more responsesbecause its starting of my carrier and i have interest in this field and this is the better platform to boost up my carrier and its true that it gives better salary also ..................thanks and regards2 fullfill my dreamsits good , and I interest in this fieldTo provide better service at the same time to increase the fame of wipro company....bcoz wipro is best company ever.because,they trust freshers and satisfy their needs..its good companyWipro is one of the top most company and providing well equipments and standard products for society.Job securityIt’s my dream job and I do anything for this job as well as company it’s always be my first priority i want to be a CEO of Wipro I do very hard work for this position because it’s my dearm

19 Mar 2009
 Come out with an algorithm for getting the column number provided the column name in a excel sheet and vice versa. Excel has a naming convention of A,B..Z,AA,AB,AC..ZZ,AAA... This had to be converted to the column numbers. A will be 1 and AA will 27.. Also the algorithm to find the name provided column number.13 AnswersIts conversion from decimal to base 26 with some exception like there is nothing maps to zero. There might be a better way to do it.void printColumn(uint32_t col) { col --; int div = 26; int add = 26; while( col / div ) { div *= 26; } div /= 26; while( div != 1) { printf("%c", (col / div) + 'a' - 1); col = col % div; div /= 26; } printf("%c\n", col + 'a'); }Opps above does not work after ZZ. The correct one is void printColumn(uint32_t col) { int a = 26; int denominator = 1; while(a 0; i /= 26) low += i; // if value is lower than lower bound, decrease quotient by one if( denominator != 1 && col < (quotient * denominator + low) ) { quotient --; } printf("%c", quotient - 1 + 'A'); col = col - denominator * quotient; denominator /= 26; } }Show more responsesLet the size of the string asked is 3 e.g GHD . The formula to this : [ 26+26^2+...+ 26^(size-1) + (LetterIndex-1)*{26^(size-1)+....+(LetterIndex-1)*26}+Index ]In the code the above formula will use recursion to find the column number.The answer can be as simple as finding the first combination of number * i such that it is less then xcelcolvalue; ie repeat this till xcelColValue >= 26 ( 0 = 26){ int i = 1, num = 1; while((num * (i + 1)) 26){ i = 1; num++;} else i++; xcelNum -= num*i; sb.append((char) i); } if (xcelNum > 0) sb.append((char) xcelNum); return sb.toString(); }Also the above code is rough idea and not tested but gives enough idea on simplifying the solution. The code does not use lot of / and % calcuations but could elegantly find the solution. Note the Gaurd if(i > 26){ i = 1; num++;} else i++; which is important in finding the combination of num and i which multiples at least to xcelNum.I think the above is incorrect and it should be : public static String xcelString(int xcelNum) { StringBuffer sb = new StringBuffer(); while(xcelNum >= 26){ int i = 1; for(;(26 * (i + 1)) 0) sb.append((char) xcelNum); return sb.toString(); }Edge conditions aside, the program would be /* inputString - the column name. For e.g. "BZC" */ char [] columnName = inputString.toUpperCase().toCharArray(); int columnNumber = 0; for(int i = 0; i < columnName.length - 1; i++){ columnNumber = columnNumber + (int) Math.pow(26, (columnName.length - 1 - i)) * (columnName[i] - 64) ; } columnNumber = columnNumber + (columnName[columnName.length - 1] - 64); System.out.println("Column number is " + columnNumber);Edge conditions aside, the program would be /* inputString - the column name. For e.g. "BZC" */ char [] columnName = inputString.toUpperCase().toCharArray(); int columnNumber = 0; for(int i = 0; i < columnName.length - 1; i++){ columnNumber = columnNumber + (int) Math.pow(26, (columnName.length - 1 - i)) * (columnName[i] - 64) ; } columnNumber = columnNumber + (columnName[columnName.length - 1] - 64); System.out.println("Column number is " + columnNumber);int columnNumber(String col) { result = 0; for(i = 0;i< strlen(col) ; i++) { result *= 26; result + = col[i] - 'A' +1; } }int columnNumber(String col) { result = 0; for(i = 0;i< strlen(col) ; i++) { result *= 26; result + = col[i] - 'A' +1; } }public static String numToExcel(int n) { if(n 0) { int remainder = n%26; char newChar = (char) ('Z' - (26 -remainder)%26); result = newChar + result; n = (n-1)/26; } return result; }

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

24 Sep 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

17 Jun 2010
 How many rotations does earth make on its axis while going around the sun for one year.10 AnswersDepends on the Leap Year or non Leap Year 365 for Non Leap Year 366 for Leap YearThe question is flawed. It should either ask how many days earth takes in one revolution around sun, or how many days are in a year. The leap year is something imaginary humans have concocted to make the calendars look good. You can't say once is 4 years earth takes an extra day to go around the sun.It's to get you thinking about casting... the calender is a double casted to an int!Show more responses365.25 / yr I wouldn't say 365/ 366 leap year. Jain has a point.^It's either 364.25 or 366.25 depending on whether the earth spins in the same direction as it goes around the sun or not (I don't remember which it is and can't deduce it from the information that's available to me without looking it up). Imagine if the Earth did not spin at all on its axis so it would seem as if a year was equivalent to one day. It will take the Earth rotating either 264.24 or 366.25 times depending on the direction to seem like the 365.25 days that it does take.Every year it takes 365.25 rotations but while making calendar we ignore that 0.25 for 3 years and add an extra day in 4th year.365.25 is WRONG!!! Actually Anonymous is right! Just think about this (lay it out on your desk):
• How many days would there be if the earth would not revolve around its axis?
• How many days would there be if it turned once around it's axis?
• Now do again one, change the direction the earth revolves it's axis, but keep going the same direction around the sun ...
The concrete right answer is 366.25 Here you find details on the exact number (with other proof): :)All answers here are false and crap. To say a leap day is added to look good is a lie. To say 365.25 rotations is also a lie because it is 365.25 days not rotations. It takes 366.25 rotations making the 365.25 days, so that in 4 years 1461 days are made by 1465 rotations. If the Earth rotated the opposite direction then the 366.25 rotations would make 367.25 days and the 1465 rotations would make 1469 days. Simple math, but the idiots rule the world, while retarded ones worse than the idiots try to play smarter and CAN'T. Same as with Venus it takes 1.62509035863 orbits to make 0.62509035863 synod. Mathematical geometry that all cycles differ by exactly ONE. (Like the 366.2422 to produce 365.2422, and the 366.2425 to produce the 365.2425, and the 366.25 to produce the 365.25 and this is why Venus takes 1.62509035863 of 224.606267349 days to make 0.62509035863 of 583.924347116 so that if the math is not an exact balance then you have the wrong figures. 1+fractional A times one orbit = fractional A times one synod. And so 13 orbits around the sun appear from Earth as 5 times around the sun. Or more precisely when the math is checked to be exactly equal by this LAW that I discover, 13 orbits will appear as 5.00044481781 synods as seen from Earth, and 5 synods (superior conjunctions) will be 12.9988435764 orbits.This question makes no sense.It's other way around, only when earth complete one round, we call it a year. To make human calculations easy, we introduced leap yrs.

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

12 Jul 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)