Engineers are responsible for designing and building products. In an interview context, expect to be quizzed on your technical skills, and also evaluated for your ability to work as a part of a team to get things built. The specific questions you are asked will depend on what type of engineering position you are looking for. Try a specific engineering discipline, such as software engineer, electrical engineer, or mechanical engineer.
Given an array of numbers, replace each number with the product of all the numbers in the array except the number itself *without* using division.
O(size of array) time & space: First, realize that saying the element should be the product of all other numbers is like saying it is the product of all the numbers to the left, times the product of all the numbers to the right. This is the main idea. Call the original array A, with n elements. Index it with C notation, i.e. from A to A[n - 1]. Create a new array B, also with n elements (can be uninitialized). Then, do this: Accumulator = 1 For i = 0 to n - 2: Accumulator *= A[i] B[i + 1] = Accumulator Accumulator = 1 For i = n - 1 down to 1: Accumulator *= A[i] B[i - 1] *= Accumulator Replace A with B It traverses A twice and executes 2n multiplicates, hence O(n) time It creates an array B with the same size as A, hence O(n) temporary space
# A Python solution (requires Python 2.5 or higher): def mult(arr, num): return reduce(lambda x,y: x*y if y!=num else x, arr) arr = [mult(arr,i) for i in arr] # O(n^2) time, O(n) space
Create two more arrays. One array contains the products of the elements going upward. That is, B = A, B = A * A, B = B * A, and so on. The other array contains the products of the elements going down. That is, C[n] = A[n], C[n-1] = A[n] * A[n-1], and so on. Now A[i] is simply B[i-1] * C[i+1].