import java.util.*; class GFG { static double probability(int[] arr1, int[] arr2) { int N = arr1.length; int M = arr2.length; double res = 0; Arrays.sort(arr2); for (int i =…

# Searching

### Count inversions in a permutation of first N natural numbers

Count inversions in a permutation of first N natural numbersGiven an array, arr[] of size N denoting a permutation of…

### Find all possible pairs with given Bitwise OR and Bitwise XOR values

Find all possible pairs with given Bitwise OR and Bitwise XOR valuesGiven two positive integers A and B representing Bitwise…

### Count substrings having frequency of a character exceeding that of another character in a string

#include using namespace std;void update(int ind, vector& segTree, int n){ ind += n; segTree[ind]++; for (; ind > 1; ind >>= 1) { segTree[ind >>…

### Find Unique ID and Domain Name of a Website from a string

#include using namespace std; bool ischar(char x){ if ((x >= ‘A’ && x = ‘a’ && x = ‘0’ && x

### Count ways to represent a number as sum of perfect squares

Count ways to represent a number as sum of perfect squaresGiven an integer N, the task is to find the…

### Find index of an element in a Set in C++

Find index of an element in a Set in C++Given a set S consisting of N integers and an element…

### Minimize sum of absolute differences of same-indexed elements of two given arrays by at most one replacement

#include using namespace std; int minAbsoluteSumDiff(vector A, vector B, int N){ int sum = 0; int diff[N]; for (int i = 0; i < N;…

### Generate an array consisting of most frequent greater elements present on the right side of each array element

#include using namespace std; void findArray(int arr[], int n){ vector v; for (int i = 0; i < n; i++) { int ans =…

### Find the array element having equal count of Prime Numbers on its left and right

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