Articles on Trending Technologies

Technical articles with clear explanations and examples

Flip to Zeros in C++

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

Suppose we have one integer array called nums and this contains 0s and 1s. Suppose we have an operation where we pick an index i in nums and flip element at index i as well as all numbers to the right of i. We have to find the minimum number of operations required to make nums contain all 0s.So, if the input is like [1, 0, 1], then the output will be 3, operation on index 0, it will convert [0, 1, 0], then on index 1 [0, 0, 1], then index 2, [0, 0, 0].To solve this, we will ...

Read More

How to create a column with binary variable based on a condition of other variable in an R data frame?

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

Sometimes we need to create extra variable to add more information about the present data because it adds value. This is especially used while we do feature engineering. If we come to know about something that may affect our response then we prefer to use it as a variable in our data, hence we make up that with the data we have. For example, creating another variable applying conditions on other variable such as creating a binary variable for goodness if the frequency matches a certain criterion.ExampleConsider the below data frame −set.seed(100) Group

Read More

Furthest From Origin in C++

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

Suppose we have a string s where each character is either "L", "R" or "?". "L" means moved one unit left, "R" means moved one unit right, and "?" means either "L" or "R". If we are at position 0, we have to find the maximum possible distance we could be from 0 by replacing "?" with "L" or "R".So, if the input is like "LLRRL??", then the output will be 3, replace ? using L to move 5 units left and 2 units right, so maximum displacement is 3.To solve this, we will follow these steps −op := 0, ...

Read More

How to create gridlines that matches with Y-axis values in the plot created by using plot function in R?

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

When we create a plot in R and draw gridlines then the gridlines are drawn on the basis of the values provided inside the grid function, therefore, it may or may not match with the Y-axis labels. But it can be done, we just need to set the values inside the grid function to NULL.ExampleConsider the below plot −x

Read More

What happens when more restrictive access is given to a derived class method in C++

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

In this section we will discuss about interesting facts restrictive access of derived class methods in C++. We will see some examples and analyze the output to know more about restrictions of using derived class methods in C++.Example (C++)Let us see the following implementation to get better understanding −#include using namespace std; class BaseClass { public:    virtual void display(){       cout

Read More

Flipped Matrix Prequel in C++

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

Suppose we have one binary matrix. We have to find the maximum number of 1s we can get if we flip a row and then flip a column.So, if the input is like101010100then the output will be 8To solve this, we will follow these steps −n := size of rows in matrixm := size of columns in matrixret := 0Define an array row of size nDefine an array col of size ntotal := 0for initialize i := 0, when i < n, update (increase i by 1), do −for initialize j := 0, when j < m, update (increase j ...

Read More

How to reduce the space between two plots that are joined with grid.arrange in R?

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

When we join or combine plots using grid.arrange the scales of the first plot comes in between as X-axis even if the independent variable in both of the plots is same.Therefore, we might want to remove the space between the plots while joining to get only one X-axis. This can be done by using theme function.ExampleConsider the below data frame −set.seed(123) x

Read More

Coincidence Search in C++

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

Suppose we have a list of unique integers called nums. We have to find the number of integers that could still be successfully found using a standard binary search.So, if the input is like [2,6,4,3,10], then the output will be 3, as if we use binary search to look for 4, we can find it at first iteration. We can also find 2 and 10 after two iterations.To solve this, we will follow these steps −Define a function help(), this will take target, an array & nums,low := 0high := size of nums - 1while low

Read More

Large to Small Sort in C++

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

Suppose we have a list of integers nums, we have to sort the list in this manner −First element is maximumSecond element is minimumThird element is 2nd maximumFourth element is 2nd minimumAnd so on.So, if the input is like [6,3,10,4], then the output will be [10, 3, 6, 4]To solve this, we will follow these steps −Define an array retsort the array numsj := size of nums - 1i := 0while i

Read More

Beer Bottles in C++

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

Suppose we have one number n. Here n indicates n full beer bottles. If we can exchange 3 empty beer bottles for 1 full beer bottle, we have to find the number of beer bottles we can drink.So, if the input is like 10, then the output will be 14.To solve this, we will follow these steps −Define a function solve(), this will take n, ret := 0while n >= 3, do −q := n / 3ret := ret + q * 3n := n - q * 3n := n + qret := ret + nreturn retLet us see ...

Read More
Showing 26651–26660 of 61,297 articles
Advertisements