Searching

Probability of obtaining pairs from two arrays such that element from the first array is smaller than that of the second array

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 =…

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;…