Software Developer Interview Questions | Glassdoor.co.in

# Software Developer Interview Questions

17,388

Software developer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

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

7 Apr 2012
 Given an integer array which consists of numbers from 1 to N with 1 number missing find the missing number. What will you do if 2 numbers are missing?4 AnswersGiven that the summation from 1 -> N = N(N+1)/2, we can use simple math to get a solution in O(n) time. We know that our array is "missing" a number, so it's length "L", is N-1. So we know that the summation for our array if it were not missing the value X could be calculated as N(N+1)/2, or (L+1)(L+2)/2. For a given array with length L, all we need to do is calculate what the expected summation is, iterate over the array and find the actual summation, then calculate the difference. public int findMissingValue(int[] sequence) { int length = sequence.length(); int expectedSum = ((length + 1) * (length + 2)) / 2; int actualSum = 0; for (int i = 0; i < length; i++) { actualSum += sequence[i]; } return expectedSum - actualSum; }You have an array of length N filled with numbers 1 through N+1 with one number missing. 1. bitwise xor all numbers 1 to N+1 2. bitwise xor all numbers in the array 3. bitwise xor the above two numbers to get the missing number, as duplicates will cancel out If two numbers are missing this approach and the sum approach fail. In this case I can't think of a faster way than sorting the list.For 2 number missing.. First split up the array into half from first half find the first missing number and second half find the second missing number. If 2 missing numbers are in first half then again divide the first half into 2 half and find it.Show more responsesUse a bitmap: keys are 1 to N and values are true/false. Iterate over the array and populate the bitmap. Iterate over the bitmap and the missing numbers are those that have the value == false.

### Software Development Engineer I at Flipkart was asked...

20 May 2016
 Design a Data Structure SpecialStack that supports all the stack operations like push(), pop(), isEmpty(), isFull() and an additional operation getMin() which should return minimum element from the SpecialStack. All these operations of SpecialStack must be O(1). To implement SpecialStack, you should only use standard Stack data structure and no other data structure like arrays, list, etc.4 AnswersUse two stacks: one to store actual stack elements and other as an auxiliary stack to store minimum values. The idea is to do push() and pop() operations in such a way that the top of auxiliary stack is always the minimum.how it can be in O(1) all these operationsYou have to maintain 2 stack. One is where first latest element is being added second is where the top element is the minimum one. While adding the element itself you can sort the stack to find perticular position with the help of a temporary stack(third stack) Below is the code for how can you add element public void push(int n) { mainStack.push(n); if(sortedStack.isEmpty()) { sortedStack.push(n); } else { int topnumber = -1; if(n= sortedStack.peek() && !sortedStack.isEmpty()) { topnumber = sortedStack.pop(); temp.push(topnumber); } sortedStack.push(n); while(!temp.isEmpty()) { topnumber = temp.pop(); sortedStack.push(topnumber); } } } } How to get minimum with O(1) public int getMin() { int n = -1; if(!sortedStack.isEmpty()) { n = sortedStack.pop(); } return n; } This will always return with complexity as O(1)Show more responsesIn that case complexity for push and pop will be o(n) as we are finding and replacing the correct position in the stack containing minimum values, push and pop should also be constant according to question

### Software Developer at J.P. Morgan was asked...

23 Aug 2015
 Which is more efficient for searching, linked list or array?4 AnswersI said array, because we can jump directly to a particular index.Searching in array and linked list is both O(n) because you need to go thought each element or node to find the data your looking for.if array is sorted then using binary search, it will take O(log n) time. I think arrays can perform better in sorted case. If unsorted linked list and array will do it in O(n) time.Show more responsesarray - cache friendly

### Software Developer at Freshworks was asked...

13 Jul 2018
 Three Programs 1. Strings 2. Array subarray concepts 3. Operators5 AnswersThey ask Puzzle. There are 100 doors in a row, all doors are initially closed. A person walks through all doors multiple times and toggle (if open then close, if close then open) them in following way: In first walk, the person toggles every door In second walk, the person toggles every second door, i.e., 2nd, 4th, 6th, 8th, … In third walk, the person toggles every third door, i.e. 3rd, 6th, 9th, … ……… ………. In 100th walk, the person toggles 100th door. Which doors are open in the end?97th door ?1st door?Show more responses10All the doors that have odd number of factors will be open at the end

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

31 Jul 2012
 You have a list of sentences/words. How to find out the sub list that consists of a specific prefix? Ex: input: prefix="he", list = ["hello", "world", "hello world", "hey dude", "galaxy"....] output: ["hello", "hello world", "hey dude"]4 AnswersConstruct TRIE and search through it.APEW KHABAR SEMUA..For a pair of prefix and list of sentences, wouldn't it be just as efficient to just check the prefix against each sentence. If you are checking multiple prefixes constructing a trie would improve things.Show more responsesMostly the followup questions of any interview will be: imagie the dataset is big. Or whats the complexity & how will u improve it. So, its better to give the first answer as the best. :) Thats wat I did. Try creating indexes for your data to retrieve it faster. And as I already said, avoid naive approaches :)

### Software Developer at Booking.com was asked...

16 Aug 2017
 Sequence of robot moves and find circular loops in given moves sequence. sequence = "<<>>>>^v^v>><<" , < WEST,> EAST, ^ NORTH, v SOUTH. ^v this is a circular loop. find all such loops in a moves sequence.5 AnswersNot sure if robot NESW reference changes with every move. Like if robot moves EAST not for robot EAST becomes NORTH , SOUTH becomes EAST etcI believe to have written an acceptable Java answer to that: public static void main(String[] args) { String sequence = ">>>^v^v>> counters = new HashMap(); counters.put('>', ''); counters.put('^', 'v'); counters.put('v', '^'); long count = 0; char last = sequence.charAt(0); for (int i = 1; i < sequence.length(); i++) { char cur = sequence.charAt(i); if (counters.get(cur) == last) { // System.out.println("loop detected: " + last + ": " + cur); count++; } last = cur; } System.out.println(count); }Hint - two dimensional array with Boolean digits [0,0],[0,1],[1,1],[1,0]. Computing in a way that the sum turns out to be zero in case of a loop.Show more responsespublic static void main(String[] args) { String sequence = ">>>^v^v>>') x++; } System.out.println( x == 0 && y == 0); }https://www.geeksforgeeks.org/check-if-a-given-sequence-of-moves-for-a-robot-is-circular-or-not/

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

21 Apr 2012
 Write code to count the number of bytes used for the int data type.4 Answersint CountIntBitsF() { int x = sizeof(int) / 8; return x; }^^ Your answer is incorrect. Look closely at the question.int *p; int count=(char *)(p+1) - (char *)(p);Show more responsesvoid count_bytes_used() { int a = 66000, bytes=0; while (a > 0) { bytes++; a = a >> 8; } printf("BYTES USED: %d\n", bytes); }

### Software Developer at Zoho was asked...

14 Jun 2017
 Programming related to problem solving4 AnswersAnswered it with correctly.Hv u given d 1st round on 11th of june...? If yes then i want to know hd the result came out or yet to come..?When result will come for the written test on June 11??Show more responsesAny one got the results of written test happened in june 11??..

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

20 Aug 2017
 1st question : 210 points. Write a program to simulate a keyboard with given keys and their operation. You need to print the final text to STDOUT. Type of Keys: Each key affects the movement of the cursor on editor. The cursor position is identified by row and column. alpha numeric space=> this key inserts their respective symbol at cursors position and shift cursor. @ => [CAPS Lock] toggles caps lock, i.e., if CapsLock is 'ON' after this key press it will be 'OFF' and vice versa. Initially CAPS Lock in 'OFF'. # => [ENTER/New Line] inserts a new line character at cursor position and shift cursor position. < => [LEFT arrow] moves cursor to one step left (if available). If cursor is at the starting of the row, it moves to end of the row above (if available). > => [RIGHT arrow] moves cursor to one step right (if available). If cursor is at a row end it moves to starting of the row below (if available). / => [Backspace] deletes one character from the left of the cursor and move cursor one step left. It follows same direction rules as LEFT arrow key (<). ? => [Down arrow] If cursor is on last row nothing changes. The cursor moves to original column in next row if there are not enough characters in next row, cursor shifts to the end of the new row. Note: If key is pressed continuosly original column will not change with every key press. ^ => [UP arrow] If cursor is on first row nothing changes. The cursor moves to the original column (current) of the previous row, if there are not enough characters in previous row cursor shifts to the end of the previous row. Note: If key is pressed continuosly original column will not change with every key press. Example: Input: asdf#q#pqr^^23 Output: asd23f q pqr Input: One line of input characters (as defined above). Output: The formatted text. Example 1: Input asdf1# @qwe^23 Output asdf231 QWE Example 2: Input asdf1#@ qwe<<5 AnswersI tried only this question. My code cleared 11 test cases out of 18. My approach was to store every line as ArrayList of characters. Here is my code in java that was submitted : http://ideone.com/6IUGMNBelow is the Python implementation for above algorithm/question. s = raw_input() caps = 0 res = [] cur_row = 0 cur_col = 0 backup = 0 for x in s: if x=='@': if caps == 1: caps = 0 else: caps = 1 elif x=='#': if cur_col': if cur_col 0: cur_col-=1 else: if cur_row>0: cur_row-=1 cur_col=len(res[cur_row]) else: cur_col=0 elif x=='?': if cur_col==len(res[cur_row]): if cur_row 0: cur_row-=1 if cur_col 0: cur_col = len(res[cur_row-1]) res[cur_row-1] = res[cur_row-1] + res[cur_row] res = res[:cur_row] + res[cur_row+1:] cur_row-=1 else: pass else: res[cur_row] = res[cur_row][:cur_col-1] + res[cur_row][cur_col:] cur_col-=1 else: if caps==1: x = str.upper(x) else: x = str.lower(x) if res == []: res.append(x) cur_row = 0 cur_col = 1 elif cur_col < len(res[cur_row]): res[cur_row] = res[cur_row][:cur_col] + x + res[cur_row][cur_col:] cur_col+=1 else: res[cur_row] = res[cur_row]+x cur_col+=1 for line in res: print lineGiven a program compile it and print its output to STDOUT. The given language has 8 types of statements: ECHO 1 => prints the given number to STDOUT. Eg: ECHO 1 prints 1 to STDOUT EXIT => exits the program SET a 0 => assign variable a value 0, i.e. equivalent to a = 0 ADD 1 2 b => add 1(first) and 2(second) and assign its value to b(third), equivalent to b = 1 + 2. Value 3 will be assigned to variable b GOTO and LABEL LABEL 12 GOTO 12 The GOTO statement jumps to corresponding LABEL (defined by argument). The LABEL can occur either before or after GOTO statement. IF and END IF a 10 END If a(first argument) is equal to 10(second argument) then only statements between IF and END will be executed otherwise they will bot be executed. CONTINUE IF a 10 CONTINUE END CONTINUE is used inside IF END block. CONTINUE jumps to the corresponding IF statement of the block. Note: All arguments are whole numbers only. Variables names can only consist alphabetic[a-z] characters. All variables are intially 0. You don't need to SET a variable before using it. Example 1 Input SET a 0 LABEL 100 ADD a 1 a ECHO a IF a 5 EXIT END GOTO 100 Output 1 2 3 4 5 Example 2 Input SET a 1 SET b 2 SET goal 5 SET flag 0 IF flag 0 ADD a b c IF a goal ADD a a a SET flag 1 END ECHO a SET a b SET b c CONTINUE END Output 1 2 3 10Show more responseshello JECRC universitykuch to khud sai kerlo

### Software Developer at Wipro was asked...

24 Jun 2012
 Define Yourself3 Answersi am a hardworkig women iwill judge my workmy name is himani .i m doing bca from md university.i passed my 12th in 2009.i m hardworkingmy name is prem kumar.i m doing b.efrom rgpv university.i passed 12th in 2009 & i m doing hard working
4150 of 17,388 Interview Questions