Developer Interview Questions | Glassdoor.co.uk

# Developer Interview Questions

7,310

Developer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

### Financial Software Developer at Bloomberg L.P. was asked...

4 Dec 2009
 write a function that returns the first unique element in an array5 AnswersWhat the type of elements in the array? If character, set up the hash table, and scan the array. the hash table stores the index of each element. If the element appears more than once, update the table as a negetive value. After scanning, find the smallest index value from the hash table, which would be the first uniqure element. The time complex gonna be O(n), where n is the length of array.I wrote a sample program here. (I use map container here to replace hash_map. The doesnot work on my computer) #include "stdafx.h" #include #include using namespace std; static int find_unique_ele(char*,int); int _tmain(int argc, _TCHAR* argv[]) { char test = {'a','b','c','b','c','a'}; int min_index = find_unique_ele(test,6); if (min_index store_table_value; map store_table; while(i ::const_iterator test_it = store_table.find(*test); if(test_it != store_table.end()){ store_table[*test] = -1; } else{ store_table.insert(map::value_type(store_table_value(*test,i))); } i++; test++; } map::const_iterator table_it = store_table.begin(); store_table_value temp_value = *table_it; int min_index = temp_value.second; while(++table_it != store_table.end()){ temp_value = *table_it; if(temp_value.second < min_index || min_index < 0){ min_index = temp_value.second; } } return min_index; }I think in the above solution you have to scan the original array twice making it order (2n) or O(n). The 2nd scan is needed to determine the corresponding entry in the hash table whether it is unique or not. We need this to determine the first unique element in the array.Show more responsesSort the list then scan the list looking for a data item that does not match the previous item or the next item.very easy with c++ stl using unique() function or use hashtable for O(1) look -up HashTable mm = new HashTable(myArray.count()); for(int i =0; i

25 Apr 2013
 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 responsessorry 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) { 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 spacesI 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;

### Java Developer at IHS Markit was asked...

9 Nov 2010
 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 containerhttp://brainteaserbible.com/interview-brainteaser-puzzle-water-jugShow more responsesAdd 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.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.

### Analyst/Developer at Goldman Sachs was asked...

12 Jul 2011
 Given 9 ball with only one differ in weight, how to find out by measuring them only twice?4 AnswersTake 3 balls each. Weigh by keeping 3 on one side and three on other and keep the remaining 3 aside. 1. If the weigh comes as equal u know the ball with diff in weight is in the three kept aside. So again weigh by keeping one of the three on one side and one on other . If equal the third one is the one that differs in weight else ur weighing machine will tell u the one which differs in weight. 2. If initial weighing is not equal follow step one for the weigh which shows the diffDrop them from a sufficient height. If 8 balls land first your 9th is the lightest, if 1 lands first, it's heavier than rest. 1 go, do I get brownie points?The above is so stupid...even Galileo knew that couldn't happen...and that was over 300 years ago...Show more responsesIn theory, if you do the experiment in air, it is possible.

### Financial Software Developer At Bloomberg at Bloomberg L.P. was asked...

2 Aug 2010
 int i=14; if (i=15) i++; How much is i?4 Answers16You get an exception. i=15 isn't equality test, but assignment. if statement throws exception if the result of a test isn't a boolean.bagibyte is wrong no exception is thrown (in c++/c) ... the programmer made an error using '=' instead of '==' there for if (i =15) equates to true and i is set to 15 the i++ then increments it to 16Show more responsesanonymous is right, also wants to mention i=15 returns 15 and is true

### Financial Software Developer at Bloomberg L.P. was asked...

29 Apr 2010
 2 pieces of string of different length and non-uniform width, each take one hour to burn. the remaining length of a burning string doesn't tell you how much longer it burns for. with a lighter measure 45 mins.3 Answerslight one string. light the second string on both ends. when he second string will be completely burnt(that will take 30 min), light the other end of the first string. wait until the first string is burnt... et voila!!!they EACH take one hourTie both strings together and light at both ends. Let them burn for 37.5 mins.

### Financial Software Developer at Bloomberg L.P. was asked...

22 Dec 2012
 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 recursion2^n possibility...F(n) = F(n-1)+F(n-2)Show more responsesSummation(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.

### Java Developer at UBS was asked...

3 Sep 2010
 What is your age4 AnswersVeru simple questionNever heard anyone ask that question before, its a dangerous zone because you can always say its age descrimination if you do not get the job. Doesn't really matter when you're 30, but if you're 55 and someone asks you that, one can get pretty offended.Wow, this is not an appropriate question! The only thing close to that which i've heard is "when did you graduate from grad school"Show more responsesVery inappropriate indeed. If you are a female candidate, it is doubly inappropriate as it's rude to ask a lady her age.

23 Jun 2010