#include <bits/stdc++.h>
using namespace std;

string longestCommonPrefix(vector<string>& strs) {
    string out = "";
    if(strs.size() == 0 ){
        return out;
    }
    //find the minimum length string since the longest common prefix can't be more than that length
    string minLenStr = strs[0];
    for(int i = 1; i < strs.size(); i++){
        if(strs[i].length() < minLenStr.length()){
            minLenStr = strs[i];
        }
    }
    //loop over all string and match all the starting characters, update the maximum size possible based on the starting matching characters
    int end = minLenStr.length();
    for(int i = 0; i < strs.size(); i++){
        int j = 0;
        while(j < end){
            if(minLenStr[j] != strs[i][j]){
                break;
            }
            j++;
        }
        //update the maximum possible size
        if(j < end){
            end = j;
        }
    }
    return minLenStr.substr(0, end);
}

int main() {
	vector<string> vec(4);
	vec[0] = "hello";
	vec[1] = "hello World";
	vec[2] = "hell";
	vec[3] = "helloween";
	
	cout << longestCommonPrefix(vec) << endl;
	return 0;
}