Sunday, 28 Nov 2021
Category: cpp-unordered_map

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

Given an array arr[] consisting of N positive integers, the task is to count the number of pairs in the array, say (a, b) such that sum of a with its sum of digits is equal to sum of b with its sum of digits.Examples:Input: arr[] = {1, 1, 2, 2}Output: 2Explanation:Following are the pairs […]

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

#include using namespace std;  struct Node {    int data;    Node* left;    Node* right;};  Node* newNode(int d){    Node* n = new Node;    n->data = d;    n->left = NULL;    n->right = NULL;    return n;}  void findwt(Node* root, int wt[],            map& um,            int width = 0){        if (root == NULL) {        return;    }              um[width] += wt[root->data];          findwt(root->left, wt, um,           width – 1);          findwt(root->right, wt, um,           width + 1);}  void solveQueries(int wt[], Node* root,                  vector queries){            map um;          findwt(root, wt, um);              int x = 0;          for […]

#include using namespace std;  int findIndex(int arr[], int N){            int maxValue = INT_MIN;          for (int i = 0; i < N; i++) {        maxValue = max(maxValue, arr[i]);    }          map St;          for (int i = 1; i

Minimum time required to complete all tasks with alteration of their order allowedGiven a string S consisting of N characters (representing the tasks to perform) and a positive integer K, the task is to find the minimum time required to complete all the given tasks in any order, given that each task takes one unit […]

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

Count number of pairs (i, j) from an array such that arr[i] * j = arr[j] * i Given an array arr[] of size N, the task is to count the number of pairs (i, j) possible from the array such that arr[j] * i = arr[i] * j, where 1 ≤ i < j […]

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

Given an array arr[] consisting of N integers and an integer K, the task is to count the number of pairs satisfying the equation 2*(arr[i] & arr[j]) + (arr[i] ^ arr[j]) = K. Examples: Input: arr[] = {1, 5, 4, 8, 7}, K = 9Output: 2Explanation: Elements at index 0 and 3, i.e. arr[i] = […]