Engineer Interview Questions | Glassdoor.ie

# Engineer Interview Questions

2,742

engineer interview questions shared by candidates

## Top Interview Questions

Sort: RelevancePopular Date

19 Nov 2017

### 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 = 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?

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]); } }

### 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

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); } }

### ICT Student Engineer at IBM was asked...

8 Apr 2016
 There was no questions like "What would you do if..". It was more o fa free talk3 AnswersI went through my CV explaining in detail my experience, projects (college, professional) I worked on, chalenges faced while working on those projects and how I approached them and dealt with them. A bit about college experience and projects and the final project. Also gave some information about myself, what kind of person I am, what I like doing in my free time, etc. just to let them know that I am a "real" person and have interests outside work or work related.How long did it took you to get an offer letter (after the call from recruiter,confirming your selection) ?I didn't go through any recruitment agency. I applied for that position directly on IBM career website. As far as I can remember it took approximately 1-2 weeks to contact me after I sent the application and another week or two after my interview to get an offer.