[C] Sorting
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(m * nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m * n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/*\n * 1727. Largest Submatrix With Rearrangements\n *\n * You are given a binary matrix matrix of size m x n, and \n * you are allowed to rearrange the columns of the matrix in \n * any order.\n * \n * Return the area of the largest submatrix within matrix where \n * every element of the submatrix is 1 after reordering the columns \n * optimally.\n *\n * m == matrix.length\n * n == matrix[i].length\n * 1 <= m * n <= 10^5\n * matrix[i][j] is either 0 or 1.\n */\n\n#define MAX(a, b) ((a) > (b) ? (a) : (b))\n#define MIN(a, b) ((a) < (b) ? (a) : (b))\n\nint cmp(const void *a, const void *b)\n{\n    return *((int *)b) - *((int *)a);\n}\n\nint largestSubmatrix(int** matrix, int matrixSize, int* matrixColSize) {\n\n    /*\n     * Input:\n     *  **matrix\n     *  matrixSize\n     *  *matrixColSize\n     */\n\n    int **ones = (int **)malloc(sizeof(int *) * matrixSize), ans = 0;\n\n    for (int i = 0; i < matrixSize; i++) {\n        ones[i] = (int *)malloc(sizeof(int) * matrixColSize[i]);\n    }\n\n    for (int i = 0; i < matrixColSize[0]; i++) {\n\n        /* Find number of consecutive ones ending at each position */\n        for (int j = matrixSize - 1, cnt = 0; j >=0; j--) {\n            if (matrix[j][i] == 1) {\n                cnt++;\n            }\n            else {\n                cnt = 0;\n            }\n\n            ones[j][i] = cnt;\n        }\n    }\n\n    for (int i = 0; i < matrixSize; i++) {\n\n        /* Sort by consecutive ones value in descending order */\n        qsort(ones[i], matrixColSize[i], sizeof(int), cmp);\n\n        /* Compare the height and area */\n        for (int j = 0, height = INT_MAX; j < matrixColSize[i]; j++) {\n            height = MIN(height, ones[i][j]);\n            ans = MAX(ans, height * (j + 1));\n        }\n\n        free(ones[i]);\n    }\n\n    free(ones);\n\n    /*\n     * Output:\n     *  Return the area of the largest submatrix within matrix where \n     *  every element of the submatrix is 1 after reordering the columns \n     *  optimally.\n     */\n\n    return ans;\n}\n```
['Array', 'Greedy', 'C', 'Sorting', 'Matrix']