int* kWeakestRows(int** mat, int matSize, int* matColSize, int k, int* returnSize){
int** arr = (int**)calloc(*matColSize+1,sizeof(int*));
int* hash = (int*)calloc(*matColSize+1,sizeof(int));
int* ret = (int*)calloc(matSize,sizeof(int));
int count;
int n = 0;
int i = 0;
int j = 0;
int min = *matColSize;
for (i=0; i<matSize; i++)
{
count = 0;
for (j=0; j<*matColSize; j++)
{
if (mat[i][j])count++;
else break;
}
if (min > count) min = count;
if (!hash[count])
{
int* a = (int*)calloc(matSize,sizeof(int));
arr[count] = a;
}
arr[count][hash[count]] = i;
hash[count]++;
}
for (i=min; i<=*matColSize; i++)
{
for (j=0; j<hash[i]; j++)
{
if (!k) break;
ret[n++] = arr[i][j];
k--;
}
if (!k) break;
}
*returnSize = n;
return ret;
}