Software Interview Questions | Glassdoor.ie

Software Interview Questions

1,775

software interview questions shared by candidates

Top Interview Questions

Sort: RelevancePopular Date

Software Engineer at Amazon was asked...

28 Dec 2010
 you have array with n elements. How would you do circular shift of k positions? Time and space complexity?6 AnswersMake a circular linklist, and move headpointer K position to do K shifts. It's O(n) time complexity. Space is contant. (circular link list).Well, space isn't constant because you took an array and then copied it somehow to a linked list. Remember, you were given an array? If I understand the question correctly, they're asking to do a circular shift of some range of values, like the first k values in an array of length n? So if you wanted to shift right, temp = array[k] from index=k to 1 array[index] = array[index-1] array[0] = temp this would be O(k)? I mean, it would take k steps, but maybe it's somehow still O(n)oh, sorry, I misunderstood. Not k values, move everything k positions. Praveen Chettypally's answer works but the space complexity would be O(n) since there is a fully copy of the list? The simplest would probably be to make another array and copy in, starting at the (n-k)th element, going to the end, then starting at the beginning. A second array would probably be a better option than a completely different data structure. What if it has to be done in place? is there an O(n) solution?Show more responsesalright - http://stackoverflow.com/questions/876293/fastest-algorithm-for-circle-shift-n-sized-array-for-m-position shiftArray( theArray, M ): size = len( theArray ) assert( size > M ) reverseArray( theArray, 0, size - 1 ) reverseArray( theArray, 0, M - 1 ) reverseArray( theArray, M, size - 1 ) O(n) with no extra storage. Wish I could have thought of that one myself...I beieve this does the trick too: public static String shiftArray(char[] inputArray, int shiftLen) { assert(inputArray != null); int length = inputArray.length; assert(length > shiftLen); int moves = 0, from= 0, to = 0; char next, last; to = (from + shiftLen) % length; next = inputArray[from]; while(moves < inputArray.length) { last = inputArray[to]; inputArray[to] = next; next = last; from = to; to = (from + shiftLen) % length; moves++; } return String.valueOf(inputArray); }I tried the above function - shiftArray and the looks is not working: shiftItemsFromList class: class shiftItemsFromList{ public static String shiftArray(char[] inputArray, int shiftLen) { assert(inputArray != null); int length = inputArray.length; assert(length > shiftLen); int moves = 0, from= 0, to = 0; char next, last; to = (from + shiftLen) % length; next = inputArray[from]; while(moves < inputArray.length) { last = inputArray[to]; inputArray[to] = next; next = last; from = to; to = (from + shiftLen) % length; moves++; } return String.valueOf(inputArray); } } Part of the main function: System.out.println("Circle Shift N size array for M possitions:"); char [] array = {'a', 'b', 'c', 'd', 'e', 'f'}; shiftItemsFromList sh = new shiftItemsFromList(); String s = sh.shiftArray(array, 2); System.out.println("Print the Circle Shift N size array: " + s); System.out.println("DONE"); OUTPUT: Circle Shift N size array for M possitions: Print the Circle Shift N size array: cbadaf DONE

30 Mar 2018
 I show them my IOT project which works with the MQTT protocol. They ask what other protocols are available for IOT.4 AnswersI answered them that I have no idea. (lolz)BTW,what's the content roughly of 1:1 basics coding exercise.If you ask ROUGHLY, it's like a list of incomplete small programs you need to complete/solve. Like a in-class CA. The purpose of this is to understand how you solve problem (logical thinking stuffs).Show more responsesI am not from coding background and have my knowledge limited till functions. Hardly I know anything about classes and objects and other OOPS concepts. So are the questions more inclined towards OOPS concepts or can they be solved without OOPS?

Software Development Engineer at Amazon was asked...

23 Feb 2011
 difference between "hashing a string" and "encrypting a string". Then: is it possible to find two elements for which the hash is the same?3 Answersyou can't "go back" from a hash. You can go back from encription if you know the secret (say password, private key, whatever). Second question: yes but then you have a problem.1. Encryption uses a secret key while hashing does not require any key. Moreover, hash is one-way but encryption can be reversed by a decryption operation. 2. Yes, that's called hash collision, which although a low probability occurrence, does exist.Decryption of encrypted string is possible. But we cannot say same thing for hashing. Because hash is one way operation. Q2:Low probability, it is possible using brute force

27 Apr 2015
 Give a range of numbers, return 6 different numbers randomly. In O(n).3 AnswersSuppose the range from 0 to 100 1- Create and initialize an array of 101 elements, filled from 0 --> 100 2- Set the max to be the last element in the array i.e max = 100 3- Get a random number between 0 and max. r= rand(0,max) 4- Replace array[r] with array[max] and decrease max by 1(max = max -1) 5- Repeat from step 3As this question is usually posed, there is an additional constraint: the numbers are presented in a stream, and you do not have enough memory to store them all.public static void main(String[] args) { int max = 100; Integer[] nums = new Integer[max]; for (int i = 0; i < nums.length; i++) { nums[i] = i; } Collections.shuffle(Arrays.asList(nums)); for (int i = 0; i < 6; i++) { System.out.println(nums[i]); } }

12 Jul 2014
 Enumerate the following from 1 to 4, being 1 the fastest to execute and 4 the slowest: - read cpu register - disk seek - context switch - read from main memory3 Answersread cpu register-1 context switch-2 read from main memory-3 disk seek-4context switch - 31 CPU 2 Memory 3 Context switching 4 Disk

19 May 2015

Software Development Engineer I Intern at Amazon was asked...

3 Oct 2015
 Given an array of integers [1,2,3,4]. and target t = 5. Come up with a solution that will print out all the unique pairs in the array that are equal t.3 AnswersFound this very hard, but the interviewer gave subtle hints, and I eventually came up with the idea of using a nested for loop. But I was not completely correct as I had set the inner incrementer to j = 0 instead of j = i+1 .array a=new array(); foreach(int i in a) { if(i==t) { console.writeline(i.toString()); } } //c# code,i am not sure if this is what they whantedpublic class CalculateTuple { /** * @param args */ public static void main(final String[] args) { final int arr[] = { 1, 2, 3, 4 }; final int sum = 5; solution(arr, sum, false); } /** * find possible tuple for provided sum * * @param input * input array * @param expectedSum * expected sum value for the tuple * @param isCommutative * true : (1,2) != (2,1) will give you both tuple
* false : (1,2) == (2,1) are same and give you only (1,2) */ public static void solution(final int input[], final int expectedSum, final boolean isCommutative) { final Map indexedArray = new HashMap(); final Map uniquePair = new HashMap(); final int length = input.length; for (int i = 0; i < length; i++) { indexedArray.put(input[i], i); } int count = 0; for (int i = 0; i < length; i++) { final Integer integer = indexedArray.get(expectedSum - input[i]); if (integer != null && integer != i) { if (isCommutative || (null == uniquePair.get("(" + i + "," + integer + ")") && null == uniquePair.get("(" + integer + "," + i + ")"))) { System.out.println("(" + i + "," + integer + ")"); uniquePair.put("(" + i + "," + integer + ")", "(" + i + "," + integer + ")"); count++; } } } System.out.println("Found " + count); } }

Software Development Engineer II at Microsoft was asked...

24 Mar 2009
 Find exist in maze or prove its non existence.3 AnswersYou need to write a code for finding shortest path in maze. For a recursion use call stack.A-star algorithm perhaps?Keep an structure (array / binari Tree/ hash table) to "remember" if a "node" has been use to avoid loop. Building a graph and nodes to navigate trough the maze and track back on your node until you reach your first node that have no more "start node" or you have found the "exit node"

Software Development Engineer In Test (SDET) at Microsoft was asked...

1 Oct 2015
 Program to check if a "ransom note", has been taken from a particular news paper article. Which meant you were given two arrays of strings, and you had to check if the first array, could have been constructed from the second set2 AnswersNested loop checking each word in the first array against each word in the second until it finds a match, if a match has been found then you remove the word from the second arrayWe can use a hashset to store the elements of the first array and while looping through the second array, remove the element if it is present in the set. Finally if the hash set is empty, first array is constructed from the second. Time complexity is O(n).

Software Developer at McAfee was asked...

2 Apr 2013
 Nothing special ...basic questions about my CV. They asked about why you would use SQL stored procedure instead of SQL script in the web application2 Answersmainly around the securityStored procedures give us many advantages over using sql scripts and SQL ... to use Stored Procedures to enable our web and windows applications to ... Our application code that creates a dynamic SQL string might look something like: ... Let us now see why you should use a Stored Procedure rather than in-line SQL
110 of 1,775 Interview Questions