Software Engineer Interview Questions | Glassdoor.co.uk

# Software Engineer Interview Questions

2,366

Software engineer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

### Senior Software Engineer at Goldman Sachs was asked...

8 May 2010
 Write an algorithm to rotate a node of a binary tree.2 Answersvoid rotateLeft( Node p) { Node r = p.right; p.right = r.left; if (r.left != null) r.left.parent = p; r.parent = p.parent; if (p.parent == null) root = r; else if (p.parent.left == p) p.parent.left = r; else p.parent.right = r; r.left = p; p.parent = r; } void rotateRight(Node p) { Node l = p.left; p.left = l.right; if (l.right != null) l.right.parent = p; l.parent = p.parent; if (p.parent == null) root = l; else if (p.parent.right == p) p.parent.right = l; else p.parent.left = l; l.right = p; p.parent = l; }To help visualise, right rotation is shown below. Consider a given tree: R /\ / \ P C /\ / \ A B Imagine nodes as metal coins suspended by strings (branches). For right rotation: 1. Pick up node P and pull it up so that node R falls down to the right of P. 2. Take B (right child of P) and make it left child of node R. The tree has been right rotated now and looks like this: P /\ / \ A R /\ / \ B C Similar process can be applied to this tree to rotate it left. This time start by pulling up R above P. Hope it helps.

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

28 Oct 2011
 typically questions consist of book defination of class and object, polymorphism , over riding etc2 AnswersThey are interested in knowing whether you know well enough what is class and what is object. Try to give real life exampleA class is the blueprint from which individual objects are created. For example there might be a class for chairs and every chair created from this class is an object. Every chair object is unique. polymorphism - one interface can be implemented in several ways. For example a list can be implemented using an array or using linked objects. overriding - a method in the subclass with the same signature overrides the method in the super class.

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

28 Oct 2011
 write a function to find 2nd highest value in an array. Basic questions on STL library , some baisc regrex questions , difference between left join right join ( only basic stuff). I guess w3school tutorial is fine incase if you want to refresh . simple sql query using joins.2 AnswersFor sql , w3schools tutorial is enough to brush up the thingsSecond highest number in an array public class SecondHighest { public static int secondhighest(int[] arr){ if (arr == null){ return -1; } if (arr.length ==1){ return -1; } int max = arr[0] > arr[1] ? arr[0] : arr[1]; int max2 = arr[0] max){ max2 = max; max = arr[i]; } else if (arr[i] > max2){ max2 = arr[i]; } } return max2; } public static void main (String[] args){ int[] arr = {1,-2,4,7,-9,45,34,-92}; System.out.println(secondhighest(arr)); } }

### Software Engineer at Bloomberg L.P. was asked...

27 Jul 2010
 How are static members of a template class shared?2 AnswersThey are shared amongst same types.For each instantiation of the template class the static members are shared only between the objects of that class and are completely independent from static members of other instantiations of the template class. E.g. this program prints "50": #include template class A { public: static int x; }; template int A::x = 0; int main() { A a; A b; a.x = 5; std::cout << a.x << b.x << std::endl; return 0; }

### Senior Software Engineer at SAP Concur was asked...

14 Sep 2012
 How will you prevent the code in finally block from executing? The question isn't a very fair one as a good programmer would not write the code in finally block that he/she doesn't want to execute2 Answersif(false)Its just to check logic, finally will not run if system.exit(0) is called.

21 Feb 2013
 During the second interview, I was asked to implement LCA in a binary tree (not BST) on collabedit.com. I was close, but not close enough...3 Answersfunction lca(root, a, b){ var res = null; (function(subroot){ var ret = 0; if(subroot == a) ret += 1; if(subroot == b) ret += 2; // a, b can be the same // lca can be either a or b as well if( ret == 3 ) { res = subroot; return 0; } if(subroot.left != null){ ret += arguments.callee(subroot.left); } if(subroot.right != null){ ret += arguments.callee(subroot.right); } if (ret === 3) { res = subroot; return 0; } return ret; })(root); return res; }class Node { int value; int height Node next; Node right; Node parent; } public int height(Node root) { int retValue = 0; while((root=parent(root)) != NULL) { retValue+ } return retValue; } public Node LCA(Node A, Node B) { Node temp; A.height = height(A); B.height = height(B); if(A.height B.height; i--, A=parent(A)); do { A = parent(A); B = parent(B); } while (A != B); return A; }// NOT the best possible solution but an alternative: // This code gets parents of node1 and puts in an array. // Then gets parents of node2 and puts in another array. // Then goes through the list to see if it contains the first node. // NOTE: Not tried in editor, may not compile. Please use as pseudo code. public static void main(String[] args){ // assumption: Nodes are initialized and known already Node node1; Node node2; Node lca = getLCA(node1, node2); // TODO: print lcs System.out.println("LCA is: " + lca.toString(); } static Node getLCA(Node node1, Node node2){ List list1 = new ArrayList(); getParents(list1, node1); List list2 = new ArrayList(); getParents(list2, node2); for(Node n : list2){ if(list1.contains(n){ return n; } } } static void getParents(List list, Node node){ if(list == null){ return; } if(node == null){ return; } list.add(node); getParents(list, node.parent); } public class Node{ String value; Node parent; @Override public String toString() { return value; } }

### Senior Software Engineer C++ at Bloomberg L.P. was asked...

5 Jan 2014
 I completely froze on following question which could be useful in a function that reverses order of words. How would you move a chunk of memory in C++/C?2 Answersmemmove function Interviewer was really trying to pull this one out of me, but I was just stumped. He was like: "you can copy it, or you can - what?" I had no clue, never heard of it. I think this one finally destroyed my chances.i guess it can be moved by using pointer? Below is an answer on the stackoverflow http://stackoverflow.com/questions/6118432/how-to-reverse-words-one-by-one-in-c-using-pointers-and-arrays

### Software Development Engineer II at Expedia was asked...

27 Nov 2012
 Are you married? Do you have any kids? Where do you live? 2 AnswersI'm not sure how it works in the UK, but in USA, it's illegal to ask all three of those questions.I think its pretty common in Europe. I have been asked few times about whether I have a partner or not.