Pergunta de entrevista da empresa Amazon

The input to a function is an array of n elements.Output of that function is also an array where each element is product of all elements in the input array except the one with same index. Input ::::: 1 2 3 4 Output ::::: 2*3*4 1*3*4 1*2*4 1*2*3

Respostas da entrevista

Sigiloso

22 de mar. de 2011

Either run two loops nested and carry out operations ==> O(n^2) or multiply every element at first, which is O(n) and then divide each element by the product to find individual answers ==> O(n) Total time complexity => O(2n) ==> O(n)

4

Sigiloso

28 de fev. de 2012

Create the Output array such that the value in every position 'i' is n! / i. The time complexity will be O(n)