Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to get operations to convert one string to another in C++

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

Suppose we have two strings S and T. We have to find the shortest sequence of operations that changes S to T. Here the operations are basically either deleting or inserting a character.So, if the input is like S = "xxxy" T = "xxyy", then the output will be ["x", "x", "-x", "y", "+y"], this means place first two x's, then remove 3rd x, then place y then add a new y.To solve this, we will follow these steps −make a table dp of size 505 x 505Define a function help(), this will take i, j, S, T, if i ...

Read More

Find winner of an election where votes are represented as candidate names in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 875 Views

In this tutorial, we are going to write a program that finds the election winner. We will have an array of votes that each candidate got in the election. Let's see an example.Input {"A", "B", "C", "B", "A", "C", "D", "D", "A", "B", "D", "B", "A", "C", "D"}Output AHere, A and B got the same number of votes. In that case, we have to select the winner based on the alphabetical order of their names.Let's see the steps to solve the problem.Initialize an array of string with dummy data.Initialize a map with string as key and int as value.Iterate over the votes ...

Read More

How to generate a probability density distribution from a set of observations in R?

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

The probability density distribution is the synonym of probability density function. It is a function that defines the density of a continuous random variable. In R, we can use density function to create a probability density distribution from a set of observations.Examplex1

Read More

Find zeroes to be flipped so that number of consecutive 1's is maximized in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 175 Views

In this tutorial, we are going to find the zeroes count that need to be flipped to get maximum number of consecutive 1's in the array.We are going to use the sliding window approach to solve the problem. Let's see the steps to solve the problem.Initialize the array and max zeroes to be flipped.Initialize window starting, ending indexes along with the length.Store the max sub array of consecutive 1's length and starting index.Iterate over the array until ending indexes crosses the array length.If the zeroes count is less than the max zeroes count then increment the ending index and zeroes ...

Read More

How to set comma as decimal separator in R?

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

In European countries, a comma is used to separate the integral part of a number from the decimal part. Thus, we might want to create data or perform calculations with comma as decimal separator. In R, we can do this by just using the code options(OutDec=", "). Once we will type this in R console, all the numerical values with decimals will be printed with commas in place of dots.Exampleoptions(OutDec=", ") rnorm(10)Output[1] 0, 14421957 -0, 24152088 -0, 05215867 -0, 40577010 0, 19806357 -1, 49349808 [7] 0, 91085263 0, 43550033 2, 64009603 1, 17177332Examplernorm(50)Output[1] -0, 56186368 -2, 11404777 0, 99584461 -2, ...

Read More

How to save list where each element contains equal number of values to a text file in R?

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

If we want to save a list to a text file then first step would be converting that list to a data frame then write.table function can be used for saving. For example, if we have a list defined as LIST and it has elements each containing 50 values then we can convert it to a data frame as −LIST_df=as.data.frame(do.call(cbind,LIST))Now we can save it as −write.table(LIST_df,"LIST.txt")ExampleConsider the below list −x1

Read More

How to create a line chart using ggplot2 with larger width in R?

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

The width of the line chart can be increased by using size argument inside geom_line aesthetics of ggplot2. For example, if we have a data frame df that contains two numerical columns x and y, and we want to create a line chart between the two with larger width then it can be done as −ggplot(df)+geom_line(aes(x,y,size=2))ExampleConsider the below data frame −x

Read More

Program to check whether first player can win a game where players can form string char by char in C++

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

Suppose we have a list of words. Now consider a ghost game where two players can participate into it. Here players alternate appending letters to a string. And the string that is being made must be a valid prefix of a word in the list, and the player who spells out any word in the list loses. We have to check whether the first player can win or not if both players are playing optimally.So, if the input is like words = ["manage", "manager", "min"], then the output will be True, as they can play like −m [Player 1]ma [Player ...

Read More

Finding sum of digits of a number until sum becomes single digit in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 9K+ Views

In this tutorial, we are going to write a program that sums digits of the given number until it becomes a single digit. Let's see an example.Input −4543Output −7Let's see the steps to solve the problem.Initialize a number.Initialize the sum to 0.Iterate until the sum is less than 9.Add each digit of the number to the sum using modulo operatorPrint the sumExampleLet's see the code.#include using namespace std; void findTheSingleDigit(int n) {    int sum = 0;    while(n > 0 || sum > 9) {       if(n == 0) {          n = sum;          sum = 0;       }       sum += n % 10;       n /= 10;    }    cout

Read More

How to remove list elements by their name in R?

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

Data analysis not only includes mathematical operations, we have to spend a lot of time in data cleaning, data mining, feature engineering etc. One operation could be removing list elements by their name if they are not helpful to achieve our objective. The removal of the elements by using their names can be done with the help of which function.ExampleConsider the below list List1

Read More
Showing 25721–25730 of 61,297 articles
Advertisements