Skip to content

Commit ac57b99

Browse files
committed
Runtime: 32 ms (Top 32.36%) | Memory: 12.4 MB (Top 70.15%)
1 parent 401ff72 commit ac57b99

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

scripts/algorithms/S/Sum of Mutated Array Closest to Target/Sum of Mutated Array Closest to Target.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// Runtime: 32 ms (Top 32.36%) | Memory: 12.4 MB (Top 70.15%)
12
// This Question Includes Both Binary Search And bit of Greedy Concept also.
2-
// See We Know Ans Always Lies Between 0 and maximum element according to given question condition Because
3+
// See We Know Ans Always Lies Between 0 and maximum element according to given question condition Because
34
// sum value at maximum element is same as any other element greater than it.
4-
// So we get our sum from getval function after that you need to choose as to move forward(l = mid+1) or backward
5+
// So we get our sum from getval function after that you need to choose as to move forward(l = mid+1) or backward
56
// i.e.(h = mid-1) so if sum value we obtain is less than target then l = mid+1 why so??
6-
// Because 2 3 5 lets suppose you are having this array if we pick 2 as mid then sum value will be 6 whereas if we pick 3 then sum value will be 8 and 10 when we pick 5 so notice that sum will increase when we increase value and
7+
// Because 2 3 5 lets suppose you are having this array if we pick 2 as mid then sum value will be 6 whereas if we pick 3 then sum value will be 8 and 10 when we pick 5 so notice that sum will increase when we increase value and
78
// correspondingly decrease when we decrease value...So yess This is all what we did and got Accepted.
89
class Solution {
910
public:
@@ -37,7 +38,7 @@ class Solution {
3738
}
3839
else
3940
h = mid -1;
40-
41+
4142
int j = abs(k - target);
4243
if(j<min1)
4344
{
@@ -51,4 +52,4 @@ class Solution {
5152
}
5253
return ans;
5354
}
54-
};
55+
};

0 commit comments

Comments
 (0)