# Need Help in Google Kick Start Round A - Houses Problem

Here is the link to theQuestion.

``````#include<stdio.h>

void swap(int* a, int* b);
int partition (int arr[], int low, int high);
void quickSort(int arr[], int low, int high);

int main()
{
int t;
scanf("%d",&t);
for(int j=0;j<t;j++){
int n,b;
scanf("%d %d",&n,&b);
int arr[n];
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
quickSort(arr,0,n-1);
int count=0;
for(int i=0;b>0;i++){
if(i==n-1)
break;
b-=arr[i];
if(b>=0)
count++;
}
printf("Case #%d: %d\n",j+1,count);

}
}

void swap(int* a, int* b)
{
int t = *a;
*a = *b;
*b = t;
}

int partition (int arr[], int low, int high)
{
int pivot = arr[high];
int i = (low - 1);

for (int j = low; j <= high- 1; j++)
{

if (arr[j] < pivot)
{
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}

void quickSort(int arr[], int low, int high)
{
if (low < high)
{

int pi = partition(arr, low, high);

quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
``````

It is displaying Wrong Answer for this code. The code is working fine for the test cases. So where is the code failing?

You should break when i equals n because else you would never be able to include the (n-1)th element.

We have a inbuilt optimised sort. Just write
`sort(arr,arr+n);`