Answer:
#include <string>
using namespace std;
int maxLength(string list[], int listSize) {
if (listSize == 0) return 0;
int maxLen = 0;
for (int i = 0; i < listSize; i++) {
int len = list[i].length();
if (len > maxLen) {
maxLen = len;
}
}
return maxLen;
}
Step-by-step explanation:
the input to the method is an array of strings list and its size listSize. The method first checks if the size of the list is 0 and returns 0 in that case. Otherwise, it initializes a variable maxLen to keep track of the maximum length found so far, and then uses a for loop to iterate through the list of strings. For each string in the list, the length of the string is computed using the length method, and is compared with the current maximum length stored in maxLen. If the length of the current string is greater than maxLen, maxLen is updated to the length of the current string. Finally, maxLen is returned as the result of the maxLength method.