@@ -85,7 +85,21 @@ int GetTrappingRainWater(int[] elevationMap)
85
85
return waterToDrop ;
86
86
}
87
87
88
- [ Test ]
88
+ int [ ] GetProductofArrayExceptSelf ( int [ ] inputArray )
89
+ {
90
+ if ( inputArray == null || inputArray . Length == 0 )
91
+ throw new ArgumentNullException ( "inputArray needs to have elements" ) ;
92
+ var outputArray = new List < int > ( ) ;
93
+ for ( int index = 0 ; index < inputArray . Length ; index ++ )
94
+ {
95
+ outputArray . Add ( inputArray
96
+ . Where ( element => element != inputArray [ index ] )
97
+ . Aggregate ( ( firstElement , secondElement ) => firstElement * secondElement ) ) ;
98
+ }
99
+ return outputArray . ToArray ( ) ;
100
+ }
101
+
102
+ [ Test ]
89
103
public void RemoveDuplicatesFromSortedArray_1 ( )
90
104
{
91
105
var sortedArrayWithDuplicates = new int [ ] { 1 , 3 , 3 , 6 , 8 , 8 , 9 } ;
@@ -140,5 +154,16 @@ public void TrappingRainWater_6()
140
154
141
155
Assert . AreEqual ( expectedValue , rainWaterValue ) ;
142
156
}
157
+
158
+ [ Test ]
159
+ public void ProductofArrayExceptSelf_7 ( )
160
+ {
161
+ var inputArray = new int [ ] { 1 , 2 , 3 , 4 } ;
162
+ var expectedArray = new int [ ] { 24 , 12 , 8 , 6 } ;
163
+
164
+ var outputArray = GetProductofArrayExceptSelf ( inputArray ) ;
165
+
166
+ Assert . AreEqual ( expectedArray , outputArray ) ;
167
+ }
143
168
}
144
169
}
0 commit comments