We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3c085ed commit b43f5c6Copy full SHA for b43f5c6
fastPrep/amazon/3.java
@@ -26,6 +26,16 @@ public int maximizeNegativePnLMonths(int[] PnL)
26
{
27
if(!pq.isEmpty())
28
29
+ /**
30
+ * why is there another condition "(pq.peek() - PnL[i] > 0)"
31
+ * reason: we must make sure that the total sum after the conversion must be greater than the sum without change current element
32
+ * to a negative element.
33
+ * That is to say that (prevSum + pq.peek() * 2 - PnL[i] > 0) - (prevSum + PnL[i]) > 0
34
+ * (prevSum + pq.peek() * 2 - PnL[i] > 0) - (prevSum + PnL[i]) > 0
35
+ * ==> 2 * pq.peek() - 2 * PnL[i] > 0
36
+ * ==> pq.peek() > PnL[i]
37
+ */
38
+
39
if((prevSum + pq.peek() * 2 - PnL[i] > 0) && (pq.peek() - PnL[i] > 0))
40
41
currentSum = prevSum + pq.peek() * 2 - PnL[i];
0 commit comments