I took a coding sample test and I think it's really easy. They ask to find if a number appears in the array (print out YES) or not (print out NO). At first, I want come up with binary search method. But when I see their given function, I think it's not suitable to use that method.
In the description, they mention arr[] and k as the number we need to check if k appears in arr[].
char* findNumber(int arr_count, int arr[], int k)
{
int n = sizeof(arr)/sizeof(arr[0]);
for(arr_count = 0; arr_count < n; arr_count++)
{
if(arr[arr_count]==k)
cout<<"YES";
else
cout<<"NO";
}
return 0;
}
But when I compiled, it showed the output is null. I don't know why? I solved many more difficult problems. So I feel so bad when I got error in an easy task like this. Please tell me the wrong part.