## DEV Community is a community of 871,665 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Posted on

# Statement

A data compression software utilizes various steps to compress a string of data. One of the steps involves finding the count of characters that are not repeated in the string.

Write an algorithm for the software developer to find the count of characters that are not repeated in the string.

### Input Format

The input consists of a string.
compString representing the string
to be compressed.

### Output

Print an integer representing the count of characters that are not repeated in the string. If no such character is found or the input string is empty then print 0.

### Note

The input string compString is case sensitive. Uppercase characters and lowercase characters are counted as different. The input string compString consists of alphanumeric and special characters only.

### Example

Input:

``````alphaadida
``````

Output:

``````4
``````

### Explanation

** Non repeated characters are l, p ,h ,i **

## Solution 1

``````import java.util.*;
// number of repeated character in string
public class nikhil_persistent {

public static int nonRepeatedChar(String compString) {
int len = compString.length();
int arr[]=new int[len];
int n_arr[]=new int[len];
int count = 0;
for(int i = 0 ; i < len ; i++) {
for(int j=0 ; j < len ; j++) {
if(compString.charAt(i)==compString.charAt(j)) { //Comparing each char to itself and rest of element in array
count++; //counting number of occurances
}
}
n_arr[i] = count; // storing all occurances
count =0;
}
for(int i = 0 ; i< len ; i++) {
if(n_arr[i] == 1) {  // if the element is has only one occurance i.e. unique element
count++;
}
//System.out.print(n_arr[i]+" " );
}
return count; // returning count of uniq element

}
public static void main(String args[])
{
Scanner in= new Scanner(System.in);

String str = in.nextLine();
System.out.println( nonRepeatedChar(str));

}

}

``````

## Solution 2

``````import java.util.*;
// number of repeated character in string
public class nikhil_persistent {

public static int nonRepeatedChar(String compString) {
int arr[]=new int[256];
for(int i=0;i<compString.length();i++)
{
if(compString.charAt(i)!=' ')
arr[compString.charAt(i)]++;
}
int count=0;
for(int i=0;i<compString.length();i++)
{
if(arr[compString.charAt(i)]==1){
count++;
}
}
return count;
}
public static void main(String args[])
{
Scanner in= new Scanner(System.in);

String str = in.nextLine();
System.out.println( nonRepeatedChar(str));

}

}

``````