Software Engineer Interview Questions | Glassdoor

# Software Engineer Interview Questions

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 26, 2013

May 8, 2010

### Software Engineer at Cerner was asked...

Feb 12, 2013
 Design Checker/Chess game in Objected Oriented View.12 AnswersWhen did you attend the interview i.e dateI got interview in Feb 2013.is it on 02/08/2013?Show More Responsesyes, it is on Feb, 08i also attended the same day but i did not get any confirmation:(I got an offer on Tue (02/12). They may call you next week I guessYeah i hope for the best.Thanks for u r information..Can any one tell me how long does it take to receive phone interview confirmation and asking for site interview?for me, after I applied online, it only took a week to have phone interview and then they will schedule you to fly to their site.no I mean after the phone technical interview?how long does it take approximately to get the result?can anyone tell me how many days will it take to schedule the first phone call? I have applied on jan 21 but did not receive any call or email.not more than a week.

### Software Engineer at Apple was asked...

Oct 15, 2011
 Find number of ones in an integer.13 Answers1. Convert the number into bits (we assume that all our bits of size 8) 2. "And" it with 1 3. check if the bit returned is 1 or now. if it is '1' increase some counter. 4. right shift 8 times and perform go to 2or you can do the following using properties of number. every number when AND'ed with number - 1 it would eliminate one binary number.\ count = 0; while(n) { n &= (n-1); count++; }This doesn't work: 1. Convert the number into bits (we assume that all our bits of size 8) 2. "And" it with 1 3. check if the bit returned is 1 or now. if it is '1' increase some counter. 4. right shift 8 times and perform go to 2 look at the number 11: counter=0; 0x000B, look at the last byte B: 1011 and that with 1, you get 1 counter now equals 1, right shift 8 times and get 0x0000 and with 1, get 0, doesn't increment counter. so the number of 1's in 11 is 1.Show More ResponsesThis doesn't work either: or you can do the following using properties of number. every number when AND'ed with number - 1 it would eliminate one binary number.\ count = 0; while(n) { n &= (n-1); count++; } Look at n=7, which we know has no 1's in it. 7 in binary: 0111 6 in binary: 0110 n=7&6; so n=6; counter=1; loop again: 5 in binary=0101; n=6&5=0110&0101=0100=4; counter=2; We can already see this is wrong answer should be 0;Solutions provided above are used for finding out the number of ones in a binary string. If you Google for such question, both proposed answers would show up. For finding out the number of ones in an integer, I would propose the following. int NumberOfOnes(double number) { int counter = 0; if (number == 0) return 0; if (number == 1) return 1; do { if (number % 10 == 1) counter++; number = number / 10; } while (number); return counter; }Binary ones in python: def findBinOnes(integer): val = integer ones = 0 while val > 0: if val & 1 == 1: ones +=1 val = val >> 1 return ones Decimal ones in python: def findDecOnes(integer): val = integer ones = 0 while val > 0: if val % 10 == 1: ones += 1 val = val / 10 return onesjust an idea #!/usr/bin/env ruby 123456718791.to_s.scan(/1/).sizeint numOfOnes( int n ){ int num = 0; String str = Integer.toString ( n ); for(int i = 0 ; i < str.length() ; i++ ) { if ( str.charAt ( i ) == '1' ) num++; } return num; }In Perl: sub OnesInNum{ my \$number = shift; my \$count; my @numbers = split //, \$number; foreach my \$num (@numbers){ next if(\$num eq '.'); #skip decimal point \$count++ if(\$num == 1); } return \$count; }#include #include using namespace std; int CountBits(const int& number){ int test = 1; int count = 0; for (int i = 0; i < (sizeof(number)*8) ; i++){ int filter = number & test; if(filter) count++; test <<= 1; } return count; } int _tmain(int argc, _TCHAR* argv[]){ cout << CountBits(566632145) << endl; return 0; }Convert to binary and iterate. Check last big (increment counter if 1) then bit shift right to drop last bit. repeat.int main(void) { int input, counter = 0; printf("Enter integer: "); scanf("%d", &input); while(input) { if ((input & 0x0001) == 1) {counter++;} input = input >> 1; } printf("No. of 1s are: %d", counter); }Perl read fm stidn: chomp ( my \$int = ); my \$ones = \$int =~ tr/1/1/; say \$ones;

Oct 15, 2009

Aug 4, 2010

Mar 10, 2010

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

Jun 8, 2009
 Number of 1's in binary representation of integer?12 AnswersRun a loop, in which you binary-AND the integer with 1, and increment a counter, if the result is 1. Then right-shift the input-integer by 1 bit, and start over in the loopunsigned int ones(unsigned int number) { unsigned int n; for (n = 0; number != 0; number >> 1) { if (number & 1) { n++; } } return n; }unsigned int ones(unsigned int number) { unsigned int n; for (n = 0; number != 0; number >> 1) { if (number & 1) { n++; } } return n; }Show More Responsesi dnt knw wheather it correct or not.....do correct me if im wrng a=0 q=n/2 r=n%2 n=q if(r=1)then a=a++ continue....ct = 0; while (val) { ct++; val = val & (val - 1); }Several of the above work, but use preincrementpublic static int population(int x) { x = (x & 0x55555555) + ((x >> 1) & 0x55555555); x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x & 0x0F0F0F0F) + ((x >> 4) & 0x0F0F0F0F); x = (x & 0x00FF00FF) + ((x >> 8) & 0x00FF00FF); x = (x & 0x0000FFFF) + ((x >>16) & 0x0000FFFF); return x; }in C++, how about: do { sum += n&1; } while (n>>=1);int ones( ) { int n; int number = 1100110111; n = 0; while (number!=0) { int temp = number % 10; if(temp ==1 ) n++; number = number/10; } return n; }Lets consider 14(1110) is the number int CountOnes(int Number) { int n=0; while(number !=0) { if(number%2==1) n++; number >> 1; } return n; }The function takes an int and returns the number of Ones in binary representation public static int findOnes(int number) { if(number < 2) { if(number == 1) { count ++; } else { return 0; } } value = number % 2; if(number != 1 && value == 1) count ++; number /= 2; findOnes(number); return count; }All the answers above will not get you to amazon... try code the function with o(m), where m is the number of 1's in the binary representation of an integer. (hint: look up "Programming Interviews Exposed")