Programming Articles

Page 469 of 2544

Count smaller elements in sorted array in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 326 Views

In this tutorial, we will be discussing a program to count smaller elements in sorted array in C++.In this we will be given a number and our task is to count all the elements present in the sorted array which are smaller than the given number.Example#include using namespace std; int countSmaller(int arr[], int n, int x){    return upper_bound(arr, arr+n, x) - arr; } int main(){    int arr[] = { 10, 20, 30, 40, 50 };    int n = sizeof(arr)/sizeof(arr[0]);    cout

Read More

ratio_equal() in C++ with example

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 314 Views

In this article, we will be discussing the working, syntax, and examples of ratio_equal() function in C++ STL.What is ratio_equal template?ratio_equal template is inbuilt in C++ STL, which is defined in header file. ratio_equal is used to compare the two ratios. This template accepts two parameters and checks whether the given ratios are equal or not. Like we have two ratios, 1/2 and 3/6 which are equal when we simplify them but the numbers are not equal so C++ has an inbuilt template to check whether the two ratios are equal or not and return true if they are ...

Read More

Diet Plan Performance in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 2K+ Views

Suppose a dieter consumes calories[i], this indicates the calories on the i-th day. If we have an integer k, for every consecutive sequence of k days that is (calories[i], calories[i+1], ..., calories[i+k-1] for all 0 upper, so increase one point, lower = length of C, then come out from the looptemp := temp + C[right]return pointsExampleLet us see the following implementation to get better understanding −class Solution(object):    def dietPlanPerformance(self, c, k, l, u):       temp = 0       for i in range(k):          temp += c[i]       right = ...

Read More

Count smaller elements on right side using Set in C++ STL

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 328 Views

In this tutorial, we will be discussing a program to count smaller elements on right side using set in C++ STL.For this we will be provided with an array. Our task is to construct a new array and add the number of smaller elements on the right side of the current element at its position.Example#include using namespace std; void count_Rsmall(int A[], int len){    set s;    int countSmaller[len];    for (int i = len - 1; i >= 0; i--) {       s.insert(A[i]);       auto it = s.lower_bound(A[i]);       countSmaller[i] = distance(s.begin(), ...

Read More

Intersection of Three Sorted Arrays in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 568 Views

Suppose there are three integer arrays arr1, arr2 and arr3 and they are sorted in strictly increasing order, we have to return a sorted array of only the integers that appeared in all of these three arrays. So if arrays are [1, 2, 3, 4, 5], [1, 2, 5, 7, 9], and [1, 3, 4, 5, 8], so the output will be [1, 5]To solve this, we will follow these steps −define an array called rescreate three maps f1, f2 and f3for i in range 0 to length of arr1f1[arr1[i]] increase by 1for i in range 0 to length of ...

Read More

Count the number of 1’s and 0’s in a binary array using STL in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 449 Views

In this tutorial, we will be discussing a program to count the number of 1’s and 0’s in a binary array using STL in C++.For this we will be provided with an array. Our task is to count the number of 0’s and 1’s present in the array.Example#include using namespace std; // checking if element is 1 or not bool isOne(int i){    if (i == 1)       return true;    else       return false; } int main(){    int a[] = { 1, 0, 0, 1, 0, 0, 1 };    int n = sizeof(a) / sizeof(a[0]);    int count_of_one = count_if(a, a + n, isOne);    cout

Read More

Counting Inversions using Set in C++ STL

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 304 Views

In this tutorial, we will be discussing a program to count inversions using set in C++ STL.Inversion count is a measure of how near the array is to be completely sorted. If the array is already sorted, the inversion count will be 0.Example#include using namespace std; //returning inversion count int get_Icount(int arr[],int n){    multiset set1;    set1.insert(arr[0]);    int invcount = 0; //initializing result    multiset::iterator itset1;    for (int i=1; i

Read More

Split string into sentences using regex in PHP

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 519 Views

Examplefunction sentence_split($text) {    $before_regexes =       array('/(?:(?:['"„][\.!?…]['"”]\s)|(?:[^\.]\s[A-Z]\.\s)|(?:\b(?:St|Gen|Hon|Prof|Dr|Mr|Ms|Mrs|[JS]r|Col|Maj|Brig|Sgt|Capt|Cmnd|Sen|Rev|Rep|Revd)       \.\s)|(?:\b(?:St|Gen|Hon|Prof|Dr|Mr|Ms|Mrs|[JS]r|Col|Maj|Brig|Sgt|Capt|Cmnd|Sen|Rev|Rep|Revd)\.\s[A-Z]\.\s)|(?:\bApr\.\s)|(?:\bAug\.\s)|(?:\bBros\.       \s)|(?:\bCo\.\s)|(?:\bCorp\.\s)|(?:\bDec\.\s)|(?:\bDist\.\s)|(?:\bFeb\.\s)|(?:\bInc\.\s)|(?:\bJan\.\s)|(?:\bJul\.\s)|(?:\bJun\.\s)|(?:\bMar\.\s)|(?       :\bNov\.\s)|(?:\bOct\.\s)|(?:\bPh\.?D\.\s)|(?:\bSept?\.\s)|(?:\b\p{Lu}\.\p{Lu}\.\s)|(?:\b\p{Lu}\.\s\p{Lu}\.\s)|(?:\bcf\.\s)|(?:\be\.g\.\s)|(?:\besp       \.\s)|(?:\bet\b\s\bal\.\s)|(?:\bvs\.\s)|(?:\p{Ps}[!?]+\p{Pe} ))\Z/su',    '/(?:(?:[\.\s]\p{L}{1, 2}\.\s))\Z/su',    '/(?:(?:[\[\(]*\.\.\.[\]\)]* ))\Z/su',       '/(?:(?:\b(?:pp|[Vv]iz|i\.?\s*e|[Vvol]|[Rr]col|maj|Lt|[Ff]ig|[Ff]igs|[Vv]iz|[Vv]ols|[Aa]pprox|[Ii]ncl|Pres|[Dd]ept|min|max|[Gg]ovt|lb|ft|c\.?\s       *f|vs)\.\s))\Z/su',    '/(?:(?:\b[Ee]tc\.\s))\Z/su',    '/(?:(?:[\.!?…]+\p{Pe} )|(?:[\[\(]*…[\]\)]* ))\Z/su',    '/(?:(?:\b\p{L}\.))\Z/su',    '/(?:(?:\b\p{L}\.\s))\Z/su',    '/(?:(?:\b[Ff]igs?\.\s)|(?:\b[nN]o\.\s))\Z/su',    '/(?:(?:["”']\s*))\Z/su',    '/(?:(?:[\.!?…] [\x{00BB}\x{2019}\x{201D}\x{203A}"'\p{Pe}\x{0002}]*\s)|(?:\r?))\Z/su',    '/(?:(?:[\.!?…] ['"\x{00BB}\x{2019}\x{201D}\x{203A}\p{Pe}\x{0002}]*))\Z/su',    '/(?:(?:\s\p{L}[\.!?…]\s))\Z/su');    $after_regexes = array('/\A(?:)/su',    '/\A(?:[\p{N}\p{Ll}])/su',    '/\A(?:[^\p{Lu}])/su',    '/\A(?:[^\p{Lu}]|I)/su',    '/\A(?:[^p{Lu}])/su',    '/\A(?:\p{Ll})/su',    '/\A(?:\p{L}\.)/su',    '/\A(?:\p{L}\.\s)/su',    '/\A(?:\p{N})/su',    '/\A(?:\s*\p{Ll})/su',    '/\A(?:)/su',    '/\A(?:\p{Lu}[^\p{Lu}])/su',    '/\A(?:\p{Lu}\p{Ll})/su'); $is_sentence_boundary = array(false, false, false, false, false, false, false, ...

Read More

Hexspeak in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 966 Views

Suppose a decimal number can be converted to its Hexspeak representation by converting it to an uppercase hexadecimal string at first, after that replacing all occurrences of the digit 0 with the letter O, and the digit 1 with the letter I.This kind of representation is valid if and only if it consists only of the letters in the set {"A", "B", "C", "D", "E", "F", "I", "O"}.So we have a string num representing a decimal integer N, we have to find the Hexspeak representation of N if it is correct, otherwise return "ERROR". So if num = “257”, then ...

Read More

Counts of distinct consecutive sub-string of length two using C++ STL

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 168 Views

In this tutorial, we will be discussing a program to count distinct consecutive sub-string of length two using C++ STL.For this we will provided with a string. Our task is to count and print all the unique substrings of length two from the given string.Example#include using namespace std; void calc_distinct(string str){    map dPairs;    for (int i=0; i

Read More
Showing 4681–4690 of 25,433 articles
« Prev 1 467 468 469 470 471 2544 Next »
Advertisements