Q1 :- Problem:-
17 | You are given a string (STR) of length N, consisting of only the lower case English alphabet.
18 | Your task is to remove all the duplicate occurrences of characters in the string.
19 |
20 |
21 | Input : abcadeecfb
22 |
23 | Output : abcdef"
24 |
ANS :-
26 |
27 | var a = "abcbbssd"
28 | let b = new Set(a)
29 | b=[...b].join("")
30 | console.log(b)
31 |
32 | OUTPUT :- abcdef
33 |35 |
Q2 :- Problem :- You are given a string (STR) of length N, you have to print the count of all alphabet.(using maps)
37 |
38 | Input:- abcadeecfb
39 |
40 | Output:
41 | a=2
42 | b=2
43 | c=2
44 | d=1
45 | e=2
46 | f=1
47 |
ANS :-
49 |
50 | function countAplhabtes(str){
51 | const aphabletCount = new Map()
52 |
53 | for(let char of str){
54 | if(aphabletCount.has(char)){
55 | aphabletCount.set(char, aphabletCount.get(char)+1)
56 | }
57 | else{
58 | aphabletCount.set(char, 1)
59 | }
60 | }
61 | for(let [char,count] of aphabletCount){
62 | console.log(`${char} = ${count}}`)
63 | }
64 | }
65 |
66 | OUTPUT :- a=2
67 | b=2
68 | c=2
69 | d=1
70 | e=2
71 | f=1
74 |