Given an array arr[] consisting of N strings of lowercase characters and a character K such that any string may start with the character K, the task is to check if there exists any pair of strings that are starting and not starting (‘!’) with the character K. If found to be true, then print […]

Continue ReadingGenerate a permutation of first N natural numbers from an array of differences between adjacent elementsGiven an array arr[] consisting of (N – 1), the task is to construct a permutation array P[] consisting of the first N Natural Numbers such that arr[i] = (P[i +1] – P[i]). If there exists no such permutation, then […]

Continue Readingimport java.io.*;import java.util.*; class GFG { static int count(String S, int N) { char ch[] = { ‘u’, ‘o’, ‘i’, ‘e’, ‘a’ }; int j = 0; int res = 0; int count = 0; HashSet mp = new HashSet(); for (int i = 0; i < N; ++i) { if (S.charAt(i) == ch[j]) { ++count; mp.add(S.charAt(i)); if (mp.size() == 5) { res = Math.max(res, count); } } else if (j + […]

Continue Readingimport java.io.*;import java.util.*; class GFG { static int getCountPairs(int arr[], int N, int S) { HashMap mp = new HashMap(); for (int i = 0; i < N; i++) { if (!mp.containsKey(arr[i])) mp.put(arr[i], 0); mp.put(arr[i], mp.get(arr[i]) + 1); } int twice_count = 0; for (int i = 0; i < N; i++) { if (mp.get(S - arr[i]) != null) { twice_count += mp.get( S - arr[i]); } if (S - arr[i] == arr[i]) twice_count--; } return twice_count / […]

Continue Reading#include using namespace std; void countStringPairs(string a[], int n){ int ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { string p = a[i], q = a[j]; if (p[0] != q[0]) { swap(p[0], q[0]); int flag1 = 0; int flag2 = 0; for (int k = 0; k < n; […]

Continue Reading