Harry Potter used "Arania Exumai" to blast off Acromantulas the giant spider to protect Ron.
Like that you have to take a sentence as input, After that, you have to blast off for double letter sequence if exists and print the count.
Example:
Input: s = "MY DREAM COMPANY IS GOOGLE"
Output: 1
Approach
Java
import java.util.HashSet;import java.util.Vector;public class ExumiaBlast {public static void main(String[] args) {String s = "MY DREAM COMPANY IS GOOGLE";System.out.println(exumaiBlast(s));}static int exumaiBlast(String s) {Vector<String> v = new Vector<String>();int i = 0;int n = s.length();while (i < n) {String str = "";while (i < n && s.charAt(i) != ' ') {str += s.charAt(i);i++;}v.add(str);i++;}int cnt = 0;for (i = 0; i < v.size(); i++) {String p = v.get(i);HashSet<Character> st = new HashSet<Character>();for (int j = 0; j < p.length(); j++)st.add(p.charAt(j));if (st.size() != p.length())cnt++;}return cnt;}}
C++
#include <bits/stdc++.h>using namespace std;int exumaiBlast(string s){vector<string> v;int i = 0;int n = s.size();while (i < n){string str = "";while (i < n && s[i] != ' '){str += s[i];i++;}v.push_back(str);i++;}int cnt = 0;for (int i = 0; i < v.size(); i++){string p = v[i];set<char> st;for (int i = 0; i < p.size(); i++)st.insert(p[i]);if (st.size() != p.size())cnt++;}return cnt;}int main(){string s = "MY DREAM COMPANY IS GOOGLE";cout << exumaiBlast(s) << "\n";return 0;}
No comments:
Post a Comment