Least Occurring Digits

JAVA Code:-

import java.util.*;
public class Hello {

    public static void main(String[] args) {
        //Your Code Here
Scanner s=new Scanner(System.in);
String str=s.nextLine();
int l=str.length(),max=0,g=0;
char c[]=str.toCharArray();
int a[]=new int[10];
for(int i=0;i<l;i++)
{
    if(c[i]!=' ')
    {
        a[c[i]-'0']++;
    }
}
for(int i=0;i<10;i++)
{
    if(a[i]>max)
    {
        max=a[i];
    }
}
for(int i=0;i<10;i++)
{
    if(a[i]!=0)
    {
        if(a[i]<max)
        {
        max=a[i];
        g=i;
        }
    }
}
System.out.print(g);
    }
}

Comments

Popular posts from this blog

Reverse String Till Underscore

Count of common characters in two strings

RECTANGULAR SUM