# Save The Kingdom CSTR01

Practice

Author: Vanshita Tiwari
Tester: Ujjawal Gupta
Editorial:Ujjawal Gupta

Difficulty:
Easy.

Prerequisite:
Arrays.

Explanation
In This problem you have to sort the element on the basis of frequency of each element . Then print the least & max frequency element.

Solution:

Setter's Code:

import java.util.;
import java.lang.
;
import java.io.*;

class Solution_2
{
public static void main (String[] args)
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int nums[] = new int[n];
for(int i=0; i<n; i++){
nums[i] = sc.nextInt();
}
int []freq = new int[101];
for(int i=0; i<n; i++){
freq[nums[i]]++;
}
int minm_freq = Integer.MAX_VALUE;
int minm_freq_int = Integer.MAX_VALUE;
int maxm_freq_int = Integer.MIN_VALUE;
int maxm_freq = Integer.MIN_VALUE;
for(int i=1; i<101; i++){
if(freq[i] <= minm_freq && freq[i] != 0){
minm_freq_int = i;
minm_freq = freq[i];
}
if(freq[i] >= maxm_freq){
maxm_freq_int = i;
maxm_freq = freq[i];
}
}

``````  System.out.println(minm_freq_int + " " + maxm_freq_int);
``````

}
}