Server Side Programming Articles

Page 1213 of 2109

Count Triplets That Can Form Two Arrays of Equal XOR in C++

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

Suppose we have an array of integers arr. We want to select three indices like i, j and k where (0 = 0; j--) {             x1 = x1 ^ arr[j];             m[x1]++;          }          for (int j = i; j < n; j++) {             x2 = x2 ^ arr[j];             ret += m[x2];          }       }       return ret;    } }; main(){    Solution ob;    vector v = {2,3,1,6,7};    cout

Read More

Simplified Fractions in C++

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

Suppose we have an integer n, we have to find a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator

Read More

Maximum Number of Vowels in a Substring of Given Length in C++

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

Suppose we have a string s and an integer k. We have to find the maximum number of vowel letters in any substring of s with length k.So, if the input is like s = "abciiidef", k = 3, then the output will be 3To solve this, we will follow these steps −cnt := 0Define one set mfor each vowel v, doinsert v into mret := 0for initialize i := 0, when i < k, update (increase i by 1), do −cnt := cnt + (1 when s[i] is in m, otherwise 0)ret := maximum of ret and cntn := ...

Read More

Longest Substring with At Most Two Distinct Characters in C++

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

Suppose we have a string s; we have to find the length of the longest substring t that has at most 2 distinct characters.So, if the input is like "eceba", then the output will be 3 as t is "ece" which its length is 3.To solve this, we will follow these steps −Define a function lengthOfLongestSubstringKDistinct(), this will take s, k, ans := 0Define one map mn := size of s, x := 0for initialize j := 0, i := 0, when j < n, update (increase j by 1), do −(increase m[s[j]] by 1)if m[s[j]] is same as 1, ...

Read More

One Edit Distance in C++

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

Suppose we have two strings s and t; we have to check whether they are both one edit distance apart. The one edit distance has three types −Insert a character into s to get tDelete a character from s to get tReplace a character of s to get tSo, if the input is like s = "ab", t = "acb", then the output will be TrueTo solve this, we will follow these steps −n := size of s, m := size of tif n < m, then −return isOneEditDistance(t, s)for initialize i := 0, when i < m, update (increase ...

Read More

Meeting Rooms II in C++

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

Suppose there is an array of meeting time intervals. There are two times start and end times [[s1,e1],[s2,e2],...] and each pair satisfies the rule (si < ei), We have to find the minimum number of conference rooms required.So, if the input is like [[0, 30], [5, 10], [15, 20]], then the output will be 2.To solve this, we will follow these steps −define one priority queue pqsort the intervals arrayret := 0for initialize i := 0, when i < size of intervals, update (increase i by 1), do −while (not pq is empty and top element of pq

Read More

Inorder Successor in BST in C++

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

Suppose we have a binary search tree and a node in it, we have to search the in-order successor of that node in the BST. As we know that the successor of a node p is the node with the smallest key greater than p.val.So, if the input is like root = [2, 1, 3], p = 1, then the output will be 2, To solve this, we will follow these steps −Define recursive method inorderSuccessor(), this will take root and pif root null, then −return nullif val of root val val){          return inorderSuccessor(root->right, p);   ...

Read More

Maximum Size Subarray Sum Equals k in C++

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

Suppose we have an array called nums and a target value k, we have to find the maximum length of a subarray that sums to k. If there is not present any, return 0 instead.So, if the input is like nums = [1, -1, 5, -2, 3], k = 3, then the output will be 4, as the subarray [1, - 1, 5, -2] sums to 3 and is the longest.To solve this, we will follow these steps −ret := 0Define one map mn := size of numstemp := 0, m[0] := -1for initialize i := 0, when i < ...

Read More

Why scale_fill_manual does not fill the bar with colors created by using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 3K+ Views

We can manually fill the color of bars in a bar plot which is created by using ggplot2 but for this we would be needing color aesthetics already used for the bars. That means we need to use filling of bars inside aes of ggplot2 and then the colors can be mentioned inside the scale_fill_manual function.ExampleConsider the below data frame:> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Loading ggplot2 package and creating bar plot:Example> library(ggplot2) > ggplot(df, aes(x, count))+geom_bar(stat="identity")Output:Creating the bar plot by using scale_fill_manual:Example> ggplot(df, aes(x, count))+geom_bar(stat="identity")+scale_fill_manual(values=c("blue", "green", "grey", "yellow"))OutputThis ...

Read More

How to create a bar chart using plotly in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 484 Views

Plotly in R is a package specifically designed to create highly-interactive and publication-quality charts. The chart can be created by using plot_ly function of the package and there are three main arguments of plot_ly defined as x, y, and type, where x refers to the X-axis, y refers to the Y-axis and type refers to the chart type but the axes values are stored in a data frame or itself a shared.ExampleLoading plotly package:> library(plotly)Consider the below data frame:> x count df dfOutputx count 1 A 321 2 B 324 3 C 320 4 D 328Creating the bar plot for ...

Read More
Showing 12121–12130 of 21,090 articles
Advertisements