Problem Statement |
| You are given a int[] a. Perform the following transformation operation N times: replace each element a[i] with the product of all the elements of a except a[i]. All products are calculated using the values of a at the beginning of the operation. For example, if a = {1, 2, 3}, a single transformation would result in a = {2*3, 1*3, 1*2}. Return the 0-based index of the smallest element in a after all the transformations.
|
|
Definition |
| Class: | TransformingArray | Method: | minimalElement | Parameters: | int[], int | Returns: | int | Method signature: | int minimalElement(int[] a, int N) | (be sure your method is public) |
|
|
|
|
Constraints |
- | N will be between 0 and 100000, inclusive. |
- | a will contain between 1 and 50 elements, inclusive. |
- | Each element of a will be between 1 and 10000, inclusive. |
- | All elements of a will be distinct. |
|
Examples |
0) | |
| | Returns: 3 | The transformation will result in a = {2*3*4, 1*3*4, 1*2*4, 1*2*3} = {24, 12, 8, 6}. The last element is the smallest. |
|
|
1) | |
| |
2) | |
| |
3) | |
| |