class LexicalIncludePaths {

  @NotNull
  public static String findCommonParentFolder(@NotNull Collection<String> folders) {
    if (folders.isEmpty()) {
      return "";
    }

    List<String[]> splits = new ArrayList<>();
    int minSize = Integer.MAX_VALUE;
    for (String folder : folders) {
      String[] split = folder.split(UNIX_SEPARATOR);
      splits.add(split);
      minSize = Math.min(minSize, split.length);
    }

    StringBuilder buildUp = null;
    for (int i = 0; i < minSize; ++i) {
      String prior = null;
      for (String[] split : splits) {
        if (prior == null) {
          prior = split[i];
          continue;
        }
        if (!prior.equals(split[i])) {
          return buildUp == null ? "" : buildUp.toString();
        }
      }
      if (buildUp != null) {
        buildUp.append(UNIX_SEPARATOR);
      }
      if (buildUp == null) {
        buildUp = new StringBuilder(prior == null ? "" : prior);
      }
      else {
        buildUp.append(prior);
      }
    }
    return buildUp == null ? "" : buildUp.toString();
  }

}