CodeGraderBench/CodeGraderBench huggingface dataset:
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++){ cin>>a[i];}
int b[n];
for(int i=0;i<n;i++){b[i]=0;}
b[n-1]=1;
for(int i=0;i<n-1;i++){
     for(int j=i;j<n;j++){
         if(a[i]==a[j]){b[i]++;}}}
int maxindex=0;
for(int i=1;i<n-1;i++){
     if(b[maxindex]<b[i]){maxindex=i;}}
cout<<a[maxindex]<<" "<<b[maxindex];
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int argmax (int* arr, int L){
int maxindex = 0;
for(int j=1; j<L; j++){
if(arr[maxindex] < arr[j]) maxindex = j;
}
return maxindex;
}
int main(){
int n,x,z;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];}
x=argmax(arr,n);
z=arr[x];
int hist[z+1];
for(int j=0;j<z+1;j++){hist[j]=0;}
for(int k=0;k<n;k++){hist[(arr[k])]=hist[(arr[k])]+1;}
int a=argmax(hist,z+1);
cout<<a<<" "<<hist[a]<<endl;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

int main(){
int n;//size of array
cin >> n;

int arr[n];
for(int i = 0; i<n; i++)
{
cin >> arr[i];
}

int max = arr[0];
for(int i = 0; i<n; i++)
{
if (arr[i] > max) max = arr[i];
}
cout<< max;

int num=0;
for(int i = 0; i<n; i++)
{
if(arr[i] == max) num++;
}
cout<<" "<<num << endl;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main()
{
 int N;
 cin>>N;
 int a[N];
 for(int h=0; h<N; h++)
 {
 cin>>a[h];
 }
 
 int c,b, m=a[0];
 for(int i=0; i<N; i++)
{
   int b=0;
  // int m=a[0];
  for( int j=0; j<N; j++)
  {
  if(a[j]==a[i]) b++;
  }
 if(b>c)
 {
  c=b; 
  m=a[i]; 
 }
 //cout<<c; 
}
cout<<m<<" ";
cout<<c;
 }

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>

main_program(
int n;
cin>>n;
int a[n];
int b[n];
for(int i=0;i<n;i++){b[i]=0;}
for(i=0;i<n;i++){
cin>>a[i];}
int j=0;
int t=0;
int i=0;
while(i<n){
while(j<n){
if(a[i]==a[j]){b[i]++;}
j++;)}
i++;
}
int z=b[0];
for(int k;k<n;k++){
z=max(z,b[k+1]);}
int h=*z;
cout<<h<<" ";

while(x<n){if(y>=b[x+1]){int y=b[x];
for(int c=0;c<n;c++){
if(b[c]=>b[c+1]){b[c+1]=b[c];}
else if(b[c]<b[c+1])continue;}
cout<<b[n-1];

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;
int main(){
int n;cin>>n;int b[n],a[n];
for(int i=0;i<n;i++){cin>>a[i];}
for(int i=0;i<n;i++){b[i]=0;}
for(int i=0;i<n;i++){for(int j=0;j<n;j++){if(a[i]==a[j]){b[i]++;}}}
int maxvalind=0;
for(int i=0;i<n;i++){if(b[maxvalind]<b[i]){maxvalind=i;}}
cout<<a[maxvalind]<<" "<<b[maxvalind];}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<simplecpp>
main_program{
	int n,i,arr[n];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>arr[i];
	}
	cout<<arr[0]<<ends<<"4"<<endl;
	cout<<arr[1]<<ends<<"4"<<endl;
	cout<<arr[2]<<ends<<"4"<<endl;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include <iostream>

using namespace std;

int main()
{
int n;
cin>> n;
int a[n] ={};
for (int i = 0; i < n; i++)
{
	cin >> a[i];
}

int major = a[0];
int repeat = 0;

for (int i = 0; i < n; i++)
{
if (a[i] == a[0])
repeat++;
}

for (int i = 0; i < n; i++)
{
	int var= 0;
	if (a[i] != major)
	{
		for (int j = i; j < n; j++)
		{
			if (a[j] == a[i])
			var++;
		}
	}
	if (var > repeat)
	{
		repeat = var;
		major= a[i];
	}
}

cout << major << " " << repeat;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
# include <iostream>
using namespace std;
int main (){
int n;
cin >> n;
unsigned int arr[n];
for(int i=0;i<n;i++){
cin >> arr[i];}
int freq_entry[n]={0};
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
if(arr[j]==arr[k]){
freq_entry[j]++;}
}
}
int max_freq=freq_entry[0];
for(int i=1;i<n;i++){
if (freq_entry[i]> max_freq){
max_freq=freq_entry[i];}}
int x=0;
while(x>=0){
if (max_freq==freq_entry[x]) cout << arr[x];break;
x++; }
cout << " " << max_freq << "\n";
while(max_freq>0){
max_freq--;
for(int y=0;y<n;y++){
if (freq_entry[y]==max_freq){ cout<< arr[y];
cout << " " << max_freq << "\n";break;}
} 
}
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>

using namespace std;

int main(){
	int n,a;
	cin>>n;
	int arr[n];
	int carr[n];
	int iarr[n];
	for(int i=0;i<n;i++){
		cin>>a;
		arr[i]=a;
	}
	for(int i=0;i<n;i++){
		carr[i]=0;
	}
	for(int i=0;i<n;i++){
		iarr[i]=0;
	}
	int j;
	for(int i=0;i<n;i++){
		int a;a=arr[i];
		iarr[i]=a;
		for(int j=0;j<i;j++){
			if (iarr[j]==iarr[i]) iarr[i]=0;
		}
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			int c=0;
			if (iarr[i]==arr[j]) c=c+1;
		}
		carr[i]=c;
	}	
	for(i=0;i<n;i++){
		if (iarr[i]!=0) cout<<iarr[i]<<carr[i];
	}
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
#include<cmath>
using namespace std;

int maxarr(int num, int *arr){
    int max=0;
    for(int i=0;i<num;i++){
        if(max<arr[i]) max = arr[i];
    }
    for(int j=0;j<num;j++){
        if(arr[j]==max) return j;
    }
}

int main(){
    int n;
    cin>>n;
    int NC[n];
    for(int i=0;i<n;i++){cin>>NC[i];}
    int freq[n];
    for(int t=0;t<n;t++){
        freq[t]=0;
    }
    for(int l=0;l<n;l++){
        for(int m=0;m<n;m++){
            if(NC[l]==NC[m]) freq[l]++;
        }
    }
    int tar = maxarr(n, freq);
    cout<<NC[tar]<<" "<<freq[tar];
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

int main(){
int n,m=1,a=0;
cin>>n;
int arr[20],num[40];
for(int i=0;i<n;i++){
cin>>arr[i];
}
/*cout<<n;
for(int i=0;i<n;i++){
cout<<arr[i];
}*/

/*for(int i=0;i<n;i++){
if (i==0){for(int j=i+1;j<n;j++){
if(arr[j] == arr[i]) m++;}
num[a]=arr[i];
num[a+1]=m;
a=a+2;
m=1;
}

else {for(int k=0;k<i;k++)
if(arr[k]!=arr[i]){ 
for(int j=i+1;j<n;j++){
if(arr[j] == arr[i])m++;}
num[a]=arr[i];
num[a+1]=m;
a=a+2;
m=1;
}
else break;
}
}
for(int i=0;i<=a;a=a+2)
cout<<num[i]<<num[a+1];*/
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
if(arr[j]==arr[i]) m++;
}
num[a]=arr[i];
num[a+1]=m;
m=1;
a=a+2;
}
/*for(int i=0;i<2*n;i=i+2)
{cout<<num[i]<<num[i+1];}*/
int maxindex=1;
for(int i=1;i<2*n;i=i+2){
if(num[maxindex]<num[i]) maxindex=i;
}
for(int i=1;i<2*n;i=i+2){
  if(num[i]==num[maxindex]){
cout<<num[i-1]<<" "<<num[maxindex]<<endl;
}
}
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++)
		cin >> a[i];
	int freq[n]={0};
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n; j++)
		{
			if(a[i]==a[j])
				freq[i]++;
		}
	}
	int index=0;
	int max=0;
	for(int i=0; i<n; i++)
	{
		if(freq[i]>max)
		{
			index=i;
			max = freq[i];
		}	
	}
	cout << a[index] <<" "<<max<<endl;
	
	return 0;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: B
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include <simplecpp>
void swap (int *a, int *b)
{
    int temp;
    temp = *a;
    *a = *b;
    *b = temp;
}
int argmax (int *seq1, int L)
{
        int maxindex = 0;
        for(int j=1; j<L; j++){
                if(seq1[maxindex] < seq1[j]) maxindex = j;
        }
        return maxindex;
}
void selection_sort (int *data, int n)
{
    for(int i=n; i>1;i--)
    {
        int maxindex = argmax(data,i);
        swap(&data[maxindex],&data[i-1]);
    }
}
main_program
{
int n1;
cin>>n1;
int seq[n1];
for(int i=0;i<n1;i++)
	{
	cin>>seq[i];
	}
cout<<endl;
selection_sort(seq,n1);

int a[n1]={0};
a[0]=1;
for(int i=1;i<n1;i++)
	{
	int j=1;
	if (seq[i]==seq[i-1])
		{
		while (seq[i]==seq[i-1])
			{a[j]++;}
		}
	j=j+1;	
	}
int k=sizeof(a);
int s=argmax(a,k);
cout<<s;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: C
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int maxn=0;
int maxfreq=0;
int x=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]>maxn)
maxn=a[i];
}
for(int i=0;i<=maxn;i++)
{
int freq=0;
for(int j=0;j<n;j++)
{
if(a[j]==i) freq++;
}
if(freq>maxfreq)
{
maxfreq=freq;
x=i;
}
}
cout<<x<<" "<<maxfreq;
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: A
Problem: Write a C++ program to take user input n, the size of a 1D integer array, followed by the array entries as inputs. The program should then determine the majority element of the array, i.e., the element which occurs the most often. It should then display the majority element and how many times it occurs in the array. You may assume that the array contains only non-negative numbers. You may also assume that the array contains only one majority element. 

Input Format - Integers n, followed by elements of the integer-valued array.
Output Format - Print the values of the majority elements followed by frequency (a separate line for each element). 

Constraints
n is a positive integer, n >= 1 and n < 20

Sample input	12	3 1 2 1 2 3 2 1 3 3 2 1
Sample output 	3 4	1 4	2 4

Student submission:
#include<iostream>
using namespace std;

void cin_numbers(int *A, int n){
for(int i=0; i<n; i++) cin>>A[i];
}


void create_histogram(int *A,int *freq,int n){
for (int i=0; i<n; i++) {
	for (int j=0; j<n; j++){
		if(A[j]==A[i]) {
		freq[i]++;
		}
	}
	}
}

int argmax (int *freq, int n){
int maxindex = 0;
for (int i=1;i<n;i++) {
	if (freq[maxindex] < freq[i]) maxindex = i;
}
return maxindex;
}

void swap(int &a, int &b){
int temp = a;
a=b;
b = temp;
}

void selectionsort(int *freq, int n){
for (int i=n; i>0; i--){
	int maxindex = argmax(freq,i);
	swap(freq[maxindex],freq[i-1]);
	}
}


int main(){
int n; cin>>n;
int A[n]; 
cin_numbers(A,n);
int freq[n];int C[n];
for (int i=0; i<n: i++) freq[i] = 0;
create_histogram(A,freq,n);
for (int i=0; i<n;i++){
	C[i] = freq[i];
selectionsort(freq,n);
int y = freq[n-1];
for (int i=0; i<n;i++){
	if (freq[n-1]==C[i])
	return [i];
}
cout<<A[i]<<" "<<freq[n-1];
}
}

Grading criterion: Space Complexity
Rating A: Done in O(1) space
Rating B: Done in O(n) space
Rating C: Anything worse or wrong
Rating D: 0
Assigned grade: C