int array,k, size, i,c, largest;
for (i = 0; i < size; i++)
largest = array;
for (i = 1; i < size; i++)
if (largest < array[i])
largest = array[i];
Question link - https://www.codechef.com/problems/LOSTMAX . Please provide question link from next time.
YOur code is the correct code to find the largest element in each array.
However, in the question you’re trying to do, the size is not the first element of the test case. So array is not input properly. What you have to do is take each line as input in a string, and parse the string to get the integers (in C).
For C++, you can do it in an easier way using stringstream.
You can look at the editorial here. By the way, I feel this problem is hardly of ‘cakewalk’ difficulty level.