#include <solution/1233.h>
#include <stdbool.h>
#include <stdlib.h>

bool startwith(char *p, char *s)
{
    for (; *p && *s; p++, s++)
        if (*p != *s)
            return false;

    return (!*p && *s) || (!*p && !*s);
}

char **removeSubfolders(char **folder, int folderSize, int *returnSize)
{
    char **ret = malloc(sizeof(char *));
    *returnSize = 1;

    ret[0] = folder[0];
    for (int i = 1; i < folderSize; i++)
    {
        if (startwith(ret[*(returnSize)-1], folder[i]))
            continue;

        ret = realloc(ret, sizeof(char *) * ++(*returnSize));
        ret[*returnSize - 1] = folder[i];
    }

    return ret;
}
