Given a string S of N characters, the task is to calculate the total number of non-empty substrings such that at most one character occurs an odd number of times.Example: Input: S = “aba”Output: 4Explanation: The valid substrings are “a”, “b”, “a”, and “aba”. Therefore, the total number of required substrings are 4.Input: “aabb”Output: 9Explanation: The […]

Continue ReadingGiven an array arr[] consisting of N integers, the task is to find the maximum element with the minimum frequency.Examples:Input: arr[] = {2, 2, 5, 50, 1}Output: 50Explanation:The element with minimum frequency is {1, 5, 50}. The maximum element among these element is 50.Input: arr[] = {3, 2, 5, 6, 1}Output: 6Approach: The given problem […]

Continue Reading#include #include struct HashNode { int key; int value;}; const int capacity = 20;int size = 0; struct HashNode** arr;struct HashNode* dummy; void insert(int key, int V){ struct HashNode* temp = (struct HashNode*)malloc(sizeof(struct HashNode)); temp->key = key; temp->value = V; int hashIndex = key % capacity; while (arr[hashIndex] != NULL && arr[hashIndex]->key != key && arr[hashIndex]->key != -1) { hashIndex++; hashIndex %= capacity; } if (arr[hashIndex] == NULL || arr[hashIndex]->key == -1) size++; arr[hashIndex] = […]

Continue Reading#include using namespace std;void minJumps(int w[], int l[], int n){ if (n == 1) { cout prevElementPos) continue; while (currElementPos

Continue ReadingNumber of substrings having an equal number of lowercase and uppercase lettersGiven string S consisting of lowercase and uppercase letters, the task is to find the number of substrings having the equal number of lowercase and uppercase letters.Examples:Input: S = “gEEk”Output: 3Explanation:Following are the substrings having the equal number of lowercase and uppercase letters:“gE”“gEEk”“Ek”Therefore, the […]

Continue Reading#include using namespace std; int isPresent(int n, int x){ string num = to_string(n); for (int i = 0; i < num.size(); i++) { if ((num[i] - '0') == x) return i; } return -1;} int removeDigit(int n, int index){ string num = to_string(n); string ans = ""; for (int i = 0; i < num.size(); i++) { if (i != index) ans += num[i]; } if (ans == "" || (ans.size() == […]

Continue ReadingCount number of substrings having at least K distinct characters Given a string S consisting of N characters and a positive integer K, the task is to count the number of substrings having at least K distinct characters.Examples:Input: S = “abcca”, K = 3Output: 4Explanation:The substrings that contain at least K(= 3) distinct characters are:“abc”: […]

Continue Readingimport java.io.*;import java.util.HashMap; class GFG { public static void findNode(HashMap map, int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = map.getOrDefault(i + 1, 0); } int count0 = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) { count0++; } } count0 -= 1; if (count0

Continue ReadingSum of array elements whose count of set bits are unique Given an array arr[] consisting of N positive integers, the task is to find the sum of all array elements having a distinct count of set bits in the array. Examples: Input: arr[] = {8, 3, 7, 5, 3}Output: 15Explanation:The count of set bits […]

Continue ReadingCount of unique pairs (i, j) in an array such that sum of A[i] and reverse of A[j] is equal to sum of reverse of A[i] and A[j] Given an array arr[] consisting of N positive integers, the task is to find the count of unique pairs (i, j) such that the sum of arr[i] […]

Continue Reading