Developer Interview Questions
developer interview questions shared by candidates
Top Interview Questions
Software Engineer at Gemalto was asked...
how do you get an Elephant in the fridge? 30 Answerstake the Giraffe out first? Dumbo, you make a big fridge I don't know! But do you know how to tell if there's an elephant in your fridge? There's footprints in the the butter. How can you tell when there's TWO elephants in your fridge? You hear giggling inside. How can you tell when there's THREE elephants in your fridge? You can't close the door. You're welcome. Show more responses Open the fridge door, take the elephant then put it in the fridge, close the fridge door. Done Through the door. Chocolate elephant I'll hire trainer from the world best circus. Get a bigger or fridge or chop the elephant up Why do you want to put an elephant in a fridge in the first place? A trail of peanuts should do it. Don't use buns, the elephant might put on weight. Open the door and release the chain from around his leg. Depends on the size of the fridge! Show more responses Ask it nicely, but empty the fridge first. You'll want an American sized fridge though. The cheap ones that barely fit a pint of milk are no good for this. Open the fridge door and ask him to step in. What's the purpose of that? Keeping the elephant cool? LOL! I build a bigger fridge. First take everything else out of the fridge. Cut the elephant into pieces (provided it's already dead)! 1. By pieces!!! Omnomnom! Every day a new piece 2. A toy. 3. A note "an elephant". 4. A slide. 5. Big industrial fridge. 6. Wouldn't do that Show more responses if it was a picture of an Elephant on the packaging. If we are putting animals in the fridge, I can understand a Chicken for eggs, and a Cow for milk and a Pig for bacon, but what would I use an Elephant for? Shoot it. Chop it up. Take to rendering yard. Render to slurry. Collect slurry in roller tubs. Freeze dry slurry. Blend freeze dried slurry to fine powder. Scoop powder into foil bags. Heat seal. Load fridge. Why would you put an elephant in a fridge? They are used to hot climates and have little fur, I doubt they would enjoy it? Do you need to cool the elephant? A hose and water would be a much cheaper and effective way of cooling the elephant, fridges are for static items that don't generate their own heat, like a warm blooded animal, if you need to do a post mortem, I would do it there and then moving it would would likely change many factors including position of the organs etc due to the size and weight, do unless you were looking in say blood your results could be effected by the data, if it is blood it would be easier to take a sample, if you need the fridge and I mean really need it and at the size of the thing, build it, if you need only a section take only the section, it will probably fit in a fridge if necessary use an industrial one. or get a refrigerated lorry with a ramp, logs, ropes, lots of men and pull. IF ITS DEAD... Invent a shrink ray to scale down its size or create a paradox. If you're under a time limit then simply fill the room except the fridge with mice. lay fridge on back, remove all shelves. get elephant to place one foot in fridge and one in freezer, then balance on those two legs. jobs done! Mince it. One or more comments have been removed. |
The questions were not very difficult but you really need to have all the concepts crystal-clear and be ready to apply them successfully. One of the questions was "how to count the letters in this string:" "The quick brown fox jumps over the lazy dog"; 12 Answerspublic static int countWords(String str){ if(str == null || str.isEmpty()) return 0; int count = 0; for(int e = 0; e < str.length(); e++){ if(str.charAt(e) != ' '){ count++; while(str.charAt(e) != ' ' && e < str.length()-1){ e++; } }else{ e++; } } return count; } Sorry, the above version has an error!!!!!!!!!!!!!!!!!!!!!!!! concider this one: public static int countWords(String str){ if(str == null || str.isEmpty()) return 0; int count = 0; for(int e = 0; e < str.length(); e++){ if(str.charAt(e) != ' '){ count++; while(str.charAt(e) != ' ' && e < str.length()-1){ e++; } } } return count; } # That's why i love Python: len(re.findall('[a-zA-Z]', s)) Show more responses sorry u need to give input ;) ------ len(re.findall('[a-zA-Z]', "The quick brown fox jumps over the lazy dog")) It depends on what has to be considered a word. For example, if we consider a word any string between spaces, we can write it in a more compact way: public static int countWords(String str){ if(str == null || str.isEmpty()) return 0; return str.split(" ").length; } The question is how to count the characters in the string. If we can assume that the input is ASCII - always clarify first - then we know that the character range is 0-255. void count(char* str, int counts[255]) { if (str == 0) return; if (counts == 0) return; for (char *c = str; c != 0; c++) { counts[*c]++; } } First we assert the input is valid. Note that we take an additional parameter - an array of the count of each ASCII character. We loop through the string until we reach the null terminator, and we iterate a char pointer through each character in the string. For each iteration, we increment the counter in the array. Memory complexity is O(1), runtime complexity is O(n). If the input must be unicode, then we may consider alternatively using a hash table. void count(wchar_t* str, std::unordered_map& counts) { if (str == 0) return; for (char *c = str; c != 0; c++) { counts[*c]++; } } We still arrive at an O(1) memory complexity and O(n) runtime complexity (although it is worth noting that despite a hash table lookup takes O(1) like an array, the fixed cost of each lookup is higher for the hash table due to the hashing function, and in the worst case a lookup can be O(n)). The question asks to count the characters, without using String.length() you can do this: public static Pair countLetters(String s) { //If the string is null or it is empty then it will have no character if (s == null || s.isEmpty()) { //So return the pair with 0 and 0 return new Pair(0, 0); } //If we should still run the loop. boolean run = true; //The count of characters int count = 0; //The count of characters without spaces int countWithoutSpace = 0; //While we are still running (we are at a valid index) while (run) { //Then try to try { //Get the character at the current count char c = s.charAt(count); //Add one to the count as we have a valid character count++; //If the character is not a space if (c != ' ') { //Then add one to the count without spaces. countWithoutSpace++; } //If we get a StringIndexOutOfBooundsException it means that the current count is outside the length of the string. } catch (StringIndexOutOfBoundsException e) { //So stop the loop. run = false; } } //And return the pair with the count and the count without spaces. return new Pair(count, countWithoutSpace); } This returns both the count with and without spaces and does not use a built in length function. Wait..Am I missing something? string.Length will do the job? Yeah i think string.length() will do the job. failed! String.length returns the length of the String. Google asked you how many letters - in other words you cannot count the spaces. String. length returns number of unicode characters -and so includes spaces I would do this: public static int countWords(String sentence){ String noSpace; //REMOVE SPACE noSpace = sentence.replaceAll(" ", ""); return noSpace.length } And in javascript var str = "The quick brown fox jumps over the lazy dog" ; var length = str.replace(/\s/g, "").length; |
What do you know about Renishaw? 9 AnswersIs there any other questions you can remember of? I have this same interview in 2 days time The interview is quite relaxed so don't worry too much. They made me talk through a bit about me and go through my CV. Questions were mostly based on you and what you say about your CV. Some other questions that struck to me were though 1. What is your greatest achievement? 2. How do you organise your projects? 3. How do you prioritise your work? 4. Explain scenario where you had to deal with a difficult client. That's all I can remember. Goodluck! Thank you very much, I will definitely take the advice on board Show more responses Another small question, are there very many technical questions asked? They didn't ask me to program anything. They just asked questions if it related to what I said, for example if I was talking about a project they would ask what software life cycle I used. Or the types of topics I learnt during my courses and expand on them. Hi there! How long did it take for you to find out if you got the job? Hi! HR phoned me up the next morning offering me the job. Hi, some really useful info to prepare here, I have a different industrial placement interview tomorrow but a lot of the general questions sound like they should apply to both, thanks for the help. How formal was the office/interview environment? Just to be sure with what I am wearing, as I don't want to be too overdressed! It wasn't too formal, I felt relaxed and welcomed. However I did dress smartly and I met other applicants as well who were wearing suits. But I think it will depend on the company you are applying for. |
Design an algorithm to find the first unique element in an array. 8 AnswersOne possibility that comes in mind: * Walk the array, create a hashmap (key is the value in array, value is the count of such values). * Walk the array again and check the count in the hash map, once you hit 1, you have the first unique value. This is O(n) both space and time. Are you sure that this is O(n), it is definitely O(n^2), you go over all items twice. dear utk O(2n) = O(n) != O(n^2)... Show more responses Its a hashmap. It never guarantees you the order in which you inserted the elements...!! @ankush: this is where LinkedHashMap comes into play. An easier one would be to sort the array and since they are asking for the first unique element return the first element that does not appear more than once in the newly sorted array. @ankush: That does not matter, you do not need to keep the order in the hash map. You go again through the original array, so you definitely find the first unique value. The hashmap is just for bookkeeping. @kabajiegara: No, that will not work, consider array "2 1" - if you sort, you'll have "1 2" and would thus return 1, which is the wrong answer because the first unique is 2. |
A rabbit wants to climb some stairs and it can do steps of 1 or 2. How many possible paths are there to follow ( e.g 1-1-1... or 2-2-2 ... or 2-1-2-1... etc) 6 Answersuse recursion 2^n possibility... F(n) = F(n-1)+F(n-2) Show more responses Summation(i=0,floor(n/2))[(n-i)C(i)]. I'm sure this can be further simplified though. Correction on the above: Summation(i=0,floor(n/2))[(n-i)P(i)]. Summation(i=0,floor(n/2))[(n-i)C(i)] is correct. I need to sleep. Sorry. |
Software Engineer at Google was asked...
Write a function that takes the ordinal number of a column in a spreadsheet and returns the label of that column: i.e. 1 -> A 2 -> B, 26 -> Z, 27->AA 7 Answers!!!! There can be some bugs not fully tested use at your own risk =)... import java.util.ArrayList; public class OrdinalToColumn { public static void main(String[] args) { // TODO Auto-generated method stub int valueToConvert = 64; System.out.println(ordinalToColumnConversion(valueToConvert)); } private static char[] ordinalToColumnConversion(int valueToConvert) { // TODO Auto-generated method stub ArrayList numbersReverse = new ArrayList(); int sizeOfArr; int curIndex, rollBackIndex; while(valueToConvert>0){ // base conversion numbersReverse.add(valueToConvert % 26); valueToConvert /= 26; } sizeOfArr = numbersReverse.size(); curIndex = rollBackIndex = 0; while(curIndex rollBackIndex){ // borrowing can lead some cascading operation we have to roll back until all digits are more than 0 int barrowNumber = numbersReverse.get(tempIndx); // barrow from previous barrowNumber--; numbersReverse.set(tempIndx, barrowNumber); tempIndx--; int nextNumber = numbersReverse.get(tempIndx); // add to the current one nextNumber += 26; numbersReverse.set(tempIndx, nextNumber); } } else { curIndex++; } } if(sizeOfArr > 0 && numbersReverse.get(sizeOfArr-1) == 0){ // remove the highest significant bit if it is 0 numbersReverse.remove(sizeOfArr-1); sizeOfArr--; } char [] returnNumbers = new char [sizeOfArr]; for(int i = sizeOfArr-1, n=0; i>=0; --i, ++n){ returnNumbers[n] = (char)(numbersReverse.get(i)+64); // converting to capital letter } return returnNumbers; } } Here my solution in Java: public class SpreadSheetLabel { private static char LABEL[] = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; private static void printLabel(int n) { if (n = 26) { n /= 26; str.append(LABEL[(n-1) % LABEL.length]); } System.out.println(str.reverse()); } public static void main(String[] args) { for(int i = 1; i <= 2600; i++) { printLabel(i); } } } I haven't tried interwee's solution, but that code is so complex and long for such a simple problem I don't even wish to try and understand it :) Anyways, here is my simple and elegant solution in Java: // Precondition: i >=1 public static String excelNumbering(int i){ if(i >=1 && i<= 26) return ""+(char)(i+64); else return excelNumbering((i-1)/26) + excelNumbering((i-1)%26+1); } Show more responses In C++: string excelNumber(int i) { string excelStr = ""; int numAs = i / 26; int rest = i % 26; for (int j = 0; j < numAs; ++j) { excelStr += "A"; } return excelStr + (char) (rest + 64); } Not sure what is meant to happen for error cases (e.g. 0). void calc_ord(int ord, char* out) { if (ord == 0) return; int tmp = ord; char *ptr = out; while (tmp <= 26) { *ptr++ = 'A'; tmp -= 26; } *ptr++ = 'A' + tmp; } public String getName(int n) { String ret=""; while(n>0) { char c='A'+(n%26); ret=c+ret; n/=26; } return ret; } here in OBJC. Is interesting that no one in the previous answers, is calculating the base system..everyone is hardcoding 26. - (NSString *)lettersFromOrdinal:(NSUInteger)ordinal { NSMutableString *letters = [NSMutableString new]; NSUInteger base = 'Z'-'A'+1; NSUInteger labelLength = ceil(customLog(base, ordinal)); for (NSInteger i = labelLength-1; i >= 0; i--) { NSUInteger pow_ = pow(base, i); NSUInteger res = ordinal/pow_; char letter = 'A' + res - 1; [letters appendFormat:@"%c", letter]; ordinal -= res*pow_; } return [letters copy]; } |
The first coding question was to determine whether a list of integers with size N, contains all the numbers from one to N. 7 Answersint a[] = {3,2,1,4,5,6,8,7,9,10}; int sum=0; for(int i=0; i The answer provided by DG is awful. For instance:a[1,1,4] would be given as true. The answer is easier if you think of it in the opposite fashion. If it does not then there must be a duplicate or a number greater than or less than N. This is very easy to check for in O(n) time. I think good way to solve that is to use Max Heap O(n) and then go through array and check x<0, i != i+1 Show more responses In jj's solution, emptying a Max Heap would take O(nlogn) time (basically, the same idea as Heap Sort). Using that time complexity you can use any sorting algorithm that has O(nlogn) time, and then go through the sorted array and check that it only contains consecutive numbers starting with 1. In James' solution, we will need O(n) memory to check for duplicates, to do it in O(n) time. That can also be described as a kind of counting sort. Try and sort the array using counting sort where we expect each element's count to be exactly 1, and in the range [1, n]. We know that sum of numbers from 1 to N is N*(N+1)/2. First we make this calculation and then we sum the numbers in the array. If these two sum.s are equal to each other then the answer is yes, else no. This is an easy O(n) solution. Put the array in a Set (storing the sum of the numbers in a sum int as well). Step 1 check whether N*(N+1)/2 holds. If it this holds, iterate from 1 to n checking the number is there or not in the set. kilicars, your solution is badly wrong. Assuming an array of N elements, I could have n-1 elements equal to 0 and just one element equal to n * (n-1) / 2. Your algorithm would say yes |
Java Developer at IHS Markit was asked...
How would you measure 4 litres of water if you have 3 litre and 5 litre canisters? 7 Answers1) Pour water in 5 litre container 2) Pour 5 litre container into 3 litre until full. You are left with 2 litre in 5 litre container 3) Empty 3 liter container. Pour 2 litre into 3 litre container 4) Fill 5 litre container until full 5) Pour 1 litre into 3 litre container until full. Left with 4 litres in 5 litre container. 1. fill half of the 3 litre container 2. fill half of the 5 litre container http://brainteaserbible.com/interview-brainteaser-puzzle-water-jug Show more responses bit lenghty but 1)both 3 & 5l are empty. 2) fill 3l, pour in 5l, fill 3l again and pour in 5l, you'll have 1 l in 3 l. now pour this 1l somewhere then fill 3l one more time. Add 2 full measures using the 5l, remove 2 full measures with the 3l, you are left with 4l. Fill full water in the 5 litre canister, remove 3 liters of it to the 5 litre to the 3 litre canister. Keep remaining in the 5 litre canister(=2 litre) somwhere. Take another 5 litre water and perform the same procedure.= another 2 litre... 2+2 =4 litre.. done. Fill full water in the 5 litre canister, remove 3 liters of it to the 5 litre to the 3 litre canister. Keep remaining in the 5 litre canister(=2 litre) somwhere. Take another 5 litre water and perform the same procedure.= another 2 litre... 2+2 =4 litre.. done. |
Software Engineer at Accenture was asked...
You have three doors, behind one there is a prize. You choose door A, after that I ll tell you that behind door B there is no prize, do yuo keep your choice or change it ? 7 AnswersChange it. The probability for door A is 1/3, the probability for the set Door C + Door B is 2/3. The interview adds information on the set stating that Door B prob is 0, so the probability for Door C is 2/3 while Door A stays at 1/3 Balls. Once you know that there is no prize behind door B, prob(B) becomes 0. Then, since the prize must be behind A or C, and you don't know anything about them, prob(A) = prob(C) = 1/2. Any of the doors is OK. Sorry Filippo (F?) but u r wrong on this one. U may see also it in this way: in the game You ll never be told that your initial choice is wrong, the information added is only about the other two doors. This breaks the symmetry, the probability that your initial choice stays at 1/3 ( It is secluded by the bit of more information added ) , but now the prob of b goes to zero and because all the probabilities must add up to 1, the prob(c) becomes 2/3. I understand it is not intuitive, but not all the math is :) Show more responses Sorry guys. none of the above is correct. You forgot the check on the sentence, as Interviewer may be lying or not (50% probability for each of the two). If he is NOT lying than there is NO price behind B --> you have 50% it is behind A and 50% it is behind C. If he IS lying than price is behind door B (100% sure) If you draw the brances tree and put it all together, you have that: Probab. = 0,5*[(0.5*A+0.5*C] + 0.5*1*B Ossia: Probab = 0,25*A + 0.25*C + 0.5B which means that both A and C have 25% probabiity of having it right, while B has 50% to be right. Therefore answer is: "you leave door A and choose door B ". Not because this IS behind door B, but because you have a higher probability this is there. :-) my vote is with Rob. this is covered in every basic probability and statistics course. I think Andrea is bringing unneeded complexity to the question Filippo's answer would be correct if he did actually open the door when he chose door A, but because it doesn't say that. So assuming that he telling the truth and that door B does not have a prize i.e probability of a zero, door C must have a probability of 2/3 . Therefore Rob's answer is correct. One or more comments have been removed. |
Merging of Sets: Sets Users which reference other user groups. 6 AnswersRecursively Hello! When did you interview? Beginning of November Show more responses Okay. Thanks! Hi, can you provide more details about the question? Thanks! Recursively is bad due performance ;-) Iterative is the better way. |
See Interview Questions for Similar Jobs
- Software Developer
- Senior Software Engineer
- Intern
- Technology Analyst
- Software Development Engineer
- Graduate Software Engineer
- Java Developer
- Analyst
- Senior Software Developer
- Associate Software Engineer
- Consultant
- Graduate Software Developer
- Business Analyst
- Associate
- Financial Software Developer
- Software Engineer III
- Developer
- Product Manager
- Project Manager