I got this question , question was quite straight forward but still don’t know got wrong answer many time.
attaching both questions as well as my code=>
My code
int solve(int N, int y, vector<int> arr) {
// code here
int mini = *min_element(arr.begin(), arr.end());
int add = y-mini;
for(int i=0;i<N;i++)
{
arr[i] = arr[i]+add;
}
int ans=0;
for(int i=0;i<N;i++)
{
if(arr[i]==y)
{
ans++;
}
}
return ans;
}
Constraints:
2<=n<=10^5
-10^9<=y<=10^9
0<=arr[i]<=10^9
Please give your code anyone