 # GOC2001 "Table I like the Most" -Editorial

MEDIUM

### PROBLEM:

You are trying to study the trend in a large restaurant. The restaurant has three floor each with capacity of 50 tables. The tables are numbered as three digit number, such that first digit indicates the floor number and the remaining two digits indicates the table number. e.g. 123 - indicates 1st floor, table no. 23.The customer is free to occupy any table on any floor. The customer occupies the table, places an order, enjoys the food and then departs. Once the table is occupied the customer is not allowed to change the table. Assuming that maximum value occurs only for one table across all the floor taken together, from a given sequence of order entries estimate the table number being occupied maximum number of times.

Following are the constraints:

Table Numbers lie between 101 to 150, 201 to 250 and 301 to 350.

### EXPLANATION:

Very detailed explanation ideally with code snippets.
Ideally editorialist should write his own solution
and write editorial strictly following his solution.

### AUTHOR’S AND TESTER’S SOLUTIONS:

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

int main()
{
int arr, freq;
int size, i, j, c, count;
int location = 1, maximum;
int tablenum =0; int flag = 0;

/*
* Read size of array and elements in array
*/
//  printf("Enter size of array: ");
scanf("%d", &size);

//    printf("Enter elements in array: ");
for(i=0; i<size; i++)
{
scanf("%d", &arr[i]);
freq[i] = -1;
}

/*
* Counts frequency of each element
*/
for(i=0; i<size; i++)
{
count = 1;
for(j=i+1; j<size; j++)
{
if(arr[i]==arr[j])
{
count++;
freq[j] = 0;
}
}

if(freq[i]!=0)
{
freq[i] = count;
}
}

/*
* Prints frequency of each element
*/
// printf("\nFrequency of all elements of array : \n");

maximum = freq;

for (c = 1; c < size; c++)
{
if (freq[c] > maximum)
{
maximum  = freq[c];
location = c+1;
}

}
for(i=0; i<size; i++)
{
if(freq[i]!=0)
{
//printf("%d -> %d times\n", arr[i], freq[i]);

}
}

for(i=0; i<size-1; i++)
{

if(freq[i] == maximum)
if(freq[i]!= freq[i+1])
printf ("%d \n",arr[i]);
else
flag = 1;

}

if(flag == 1)
printf ("No max");

return 0;
}

``````