A C version without segment tree, done with tabulation
Intuition\nWorking on these for fun, to do it in C until Leetcode adopts ZIG.\n\nThe first approach to this was to build a small linked list for the blockers, b
# Intuition\nWorking on these for fun, to do it in C until Leetcode adopts ZIG.\n\nThe first approach to this was to build a small linked list for the blockers, but that proved too slow to be a good answer.\n\nThen the approach of a segment tree proved too complex in C for the max, from zero and the expading possible elements size, as it was indexed to the position value.\n\nThen decided to use a tabular approach, and optimize due to the constraint of being the max from zero, etc.\n\nThis meant much less memory and recursion than the segment tree.\n\n# Approach\nThis is a tabular version without a segment tree, optimizes the execution of the table changes and keeps only the required size from previous analysis of the original values.\n\nWe scan the origin for the maximum index used and the number of results to build the proper array sizes, as C is harder to do, but this ensures the minimum Space Complexity.\n\nBecause the update, insert of new blockers uses the table to scan already initialized data, this reduces the Time Complexity too.\n\n# Complexity\n- Time complexity\nConsidering the largest index number used being m, we have to iterate N x m at most without recursion. O(N x m)\n\n- Space complexity:\nWe have a dependency on the largest index number used, so O(m) being m this number.\n\n# Code\n```\n\ntypedef struct {\n    int *tree;\n    int *maxAllowed;\n    int size;\n} SegmentTree;\n\nSegmentTree* createSegmentTree(int size) {\n    SegmentTree *segTree = (SegmentTree *)malloc(sizeof(SegmentTree));\n    segTree->size = size;\n    segTree->tree = (int *)malloc(size * sizeof(int));\n    segTree->maxAllowed = (int *)malloc(size * sizeof(int));\n    for (int i = 0; i < size; i++) {\n        segTree->tree[i] = -1;\n        segTree->maxAllowed[i] = -1;\n    }\n    return segTree;\n}\n\nvoid update(SegmentTree *segTree, int index) {\n    int tempAllowed = 0;\n    int maxAllowed = 0;\n    int startIndex = 0;\n    if (segTree->tree[index] != -1) {\n        startIndex = index;\n        maxAllowed = segTree->maxAllowed[index];\n    } else {\n        for (int i = index; i >= 0; i--) {\n            if (segTree->tree[i] != -1) {\n                startIndex = i;\n                maxAllowed = segTree->maxAllowed[i];\n                break;\n            }\n        }\n    }\n    segTree->tree[index] = -2;\n    for(int i = startIndex; i< index; i++){\n        if(segTree->tree[i] == -1){\n            segTree->tree[i] = tempAllowed;\n        }\n        if(tempAllowed > maxAllowed){\n            maxAllowed = tempAllowed;\n        }\n        tempAllowed++;\n        if (segTree->tree[i] == -2) {\n            tempAllowed = 1;\n        }\n        segTree->maxAllowed[i] = maxAllowed;\n        // printf("< Node %d: %d Max: %d\\n", i, segTree->tree[i], segTree->maxAllowed[i]);\n    }\n        if(tempAllowed > maxAllowed){\n            maxAllowed = tempAllowed;\n        }\n       // printf("* Node %d: %d Max: %d (%d)\\n", index, segTree->tree[index], segTree->maxAllowed[index], maxAllowed);\n    segTree->maxAllowed[index] = maxAllowed;\n        tempAllowed = 1;\n    for(int i = index+1; i < segTree->size; i++){\n        if (segTree->tree[i] == -1) {\n            break;\n        }\n        if (segTree->maxAllowed[i] == maxAllowed && (segTree->tree[i] == -2 || segTree->tree[i] == tempAllowed)) {\n            break;\n        }\n        if (segTree->tree[i] == -2) {\n        if(tempAllowed > maxAllowed){\n            maxAllowed = tempAllowed;\n        }\n            tempAllowed = 0;\n        } else {\n            segTree->tree[i] = tempAllowed;\n        }\n        if(tempAllowed > maxAllowed){\n            maxAllowed = tempAllowed;\n        }\n        tempAllowed++;\n        segTree->maxAllowed[i] = maxAllowed;\n       // printf("> Node %d: %d Max: %d\\n", i, segTree->tree[i], segTree->maxAllowed[i]);\n    }\n   // printf("\\n\\n");\n}\n\nint query(SegmentTree *segTree, int end, int size) {\n    if ((end-size) < 0) {\n        return 0;\n    }\n        for(int i = end; i >= 0; i--){\n                if (end-i>=size) {\n                    return size;\n                }\n            if(segTree->tree[i] != -1){\n                return segTree->maxAllowed[i];\n            }\n        }\n    return 0;\n}\n\nbool isIntersected(SegmentTree *segTree, int end, int size) {\n    if ((end-size) < 0) {\n        return false;\n    }\n    int maxAllowed = query(segTree, end, size);\n    return maxAllowed >= size;\n}\n\nbool *getResults(int **queries, int queriesSize, int *queriesColSize, int *returnSize) {\n    if (queries == NULL || queriesColSize == NULL || returnSize == NULL) {\n        return NULL;\n    }\n\n    *returnSize = 0;\n    int treeSize = 0;\n    for (int i = 0; i < queriesSize; i++) {\n        if (treeSize < queries[i][1]) {\n            treeSize = queries[i][1];\n        }\n        if (queriesColSize[i] == 3 && queries[i][0] == 2) {\n            (*returnSize)++;\n        }\n    }\n    treeSize++;\n\n    bool *results = (bool *)malloc(*returnSize * sizeof(bool));\n    if (results == NULL) {\n        *returnSize = 0;\n        return NULL;\n    }\n\n    SegmentTree *segTree = createSegmentTree(treeSize);\n    int resultIndex = 0;\n\n    for (int i = 0; i < queriesSize; i++) {\n        int colSize = queriesColSize[i];\n        int *query = queries[i];\n\n        if (colSize == 2 && query[0] == 1) {\n            int value = query[1];\n            update(segTree, value);\n        } else if (colSize == 3 && query[0] == 2) {\n            int end = query[1];\n            int size = query[2];\n            results[resultIndex] = isIntersected(segTree, end, size);\n            resultIndex++;\n        }\n    }\n\n    free(segTree->tree);\n    free(segTree);\n\n    return results;\n}\n\n```
['Array', 'Dynamic Programming', 'Greedy', 'Segment Tree', 'C']