In the code below I am trying to return an array containing the longest strings of the inputArray
. However, when I use it the array outputted is empty.
vector<string> solution(vector<string> inputArray) {
int highestSize, add;
vector<string> newArray{};
for (int i = 0; i < inputArray.size(); ++i) {
highestSize = max(int(inputArray[i].length()), highestSize);
}
for (int i = 0; i < inputArray.size(); ++i) {
if (inputArray[i].length() == highestSize) {
newArray[add] = inputArray[i];
++add;
}
}
return newArray;
}