-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeast Repeating Character.txt
89 lines (65 loc) · 1.47 KB
/
Least Repeating Character.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<bits/stdc++.h>
using namespace std;
bool compar(pair<char,int> i,pair<char,int> j)
{
return i.second<=j.second;
}
int main(){
map<char,int> omap;
string text="abcbdad";
for(int i=0;i<text.size();i++){
omap[text[i]]++;
}
for(auto i:omap)
{
cout<<i.first<<" "<<i.second<<endl;
}
pair<char,int> smallestCharacter=*min_element(omap.begin(),omap.end(),compar);
cout<<smallestCharacter.first<<smallestCharacter.second<<endl;
}
// output-
// a 2
// b 2
// c 1
// d 2
// c1
Java:
import java.io.*;
import java.util.*;
public class dmeo{
public static void main(String args[])
{
String wrd="abadbda";
String newwrd=new String();
SortedMap<Character,Integer> hmap=new TreeMap<>();
for(int i=0;i<wrd.length();i++)
{
if(hmap.containsKey(wrd.charAt(i)))
{
hmap.put(wrd.charAt(i),hmap.get(wrd.charAt(i))+1);
}
else
{
hmap.put(wrd.charAt(i),1);
}
}
for(Entry<Character,Integer> i:hmap.entrySet())
{
System.out.println(i.getKey()+" "+i.getValue());
}
System.out.println(Collections.min(hmap));
}
}
python:
map={}
str="abadbda"
newwrd=""
for i in str:
if i in map.keys():
map[i]+=1
elif i.isalpha():
newwrd+=i
map[i]=1
for i in map:
print(i,map[i])
print(min(map.values()))