Saturday, 4 Dec 2021
Category: HashTable

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 […]

#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] = […]

Number 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 […]

#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() == […]

Count 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”: […]

import 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

Count 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] […]