#Language - C#
#Below program can store all the least occuring characters in a string.
#Time Complexity - O(N)
Approach :
-
Created list to store the east occuring characters in a string and initialized temporary variable value to 1 (any character in string can occur at minimun once).
-
Iterated string and got the count of character using LINQ.
-
If the count of the character is less than or equal to temp variable, assign the count value to temp varibale and add that character to list.
using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
public static void Main()
{
string s =Console.ReadLine().ToLower();
List<char> list = new List<char>();
int temp=1;
char c =' ';
for(int i=0;i<s.Length;i++)
{
int j = s.Where(t => t.Equals(s[i])).Count();
if(j<=temp)
{
temp=j;
list.Add(s[i]);
}
}
foreach(var v in list)
Console.WriteLine(v);
}
}