Articles on Trending Technologies

Technical articles with clear explanations and examples

Find repeated character present first in a string in C++

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

Suppose we have a string; we have to find first character that is repeated. So is the string is “Hello Friends”, the first repeated character will be l. As there are two l’s one after another.To solve this, we will use the hashing technique. Create one hash table, scan each character one by one, if the character is not present, then insert into hash table, if it is already present, then return that character.Example#include #include using namespace std; char getFirstRepeatingChar(string &s) {    unordered_set hash;    for (int i=0; i

Read More

Find minimum sum of factors of number using C++.

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

Here we will see how to get a minimum sum of factors of a given number. Suppose a number is 12. We can factorize this in different ways −12 = 12 * 1 (12 + 1 = 13)12 = 2 * 6 (2 + 6 = 8)12 = 3 * 4 (3 + 4 = 7)12 = 2 * 2 * 3 (2 + 2 + 3 = 7)The minimum sum is 7. We will take a number, and try to find the minimum factor sum. To get the minimum factor sum, we have to factorize the number as long ...

Read More

Whitespaces in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 1K+ Views

A Perl program does not care about whitespaces. Following program works perfectly fine −#!/usr/bin/perl print    "Hello, world";But if spaces are inside the quoted strings, then they would be printed as is. For example −Example#!/usr/bin/perl # This would print with a line break in the middle print "Hello          world";OutputThis will produce the following result −Hello       worldAll types of whitespace like spaces, tabs, newlines, etc. are equivalent to the interpreter when they are used outside of the quotes. A line containing only whitespace, possibly with a comment, is known as a blank line, and ...

Read More

Find safe cells in a matrix in C++

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

Suppose we have a matrix mat[][]. It has character Z and P. The Z is the zombie and P is the plant. And another character * is a bare land. A zombie can attack the plant, when plant is adjacent to zombie. We have to find number of plants, that are safe from zombie. Suppose the matrix is like below −So there are only two plants that are safe.We will traverse the matrix element by element, then when the current element is a plant, then check that the plant is surrounded by zombie or not, if not then increase the ...

Read More

Single and Double Quotes in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 848 Views

You can use double quotes or single quotes around literal strings as follows −Example#!/usr/bin/perl print "Hello, world"; print 'Hello, world';OutputThis will produce the following result −Hello, world Hello, world$There is an important difference between single and double-quotes. Only double quotes interpolate variables and special characters such as newlines , whereas a single quote does not interpolate any variable or special character. Check below example where we are using $a as a variable to store a value and later printing that value −Example#!/usr/bin/perl $a = 10; print "Value of a = $a"; print 'Value of a = $a';OutputThis will produce the ...

Read More

Find Selling Price from given Profit Percentage and Cost in C++

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

Consider we have the selling price, and percentage of profit or loss is given. We have to find the cost price of the product. The formula is like below −$$Cost Price=\frac{Sell Price∗100}{100+percentage profit}$$ $$Cost Price=\frac{Sell Price∗100}{100+percentage loss}$$Example#include using namespace std; float priceWhenProfit(int sellPrice, int profit) {    return (sellPrice * 100.0) / (100 + profit); } float priceWhenLoss(int sellPrice, int loss) {    return (sellPrice * 100.0) / (100 - loss); } int main() {    int SP, profit, loss;    SP = 1020;    profit = 20;    cout

Read More

Find N Arithmetic Means between A and B using C++.

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

Suppose we have three integers A, B and N. We have to find N arithmetic means between A and B. If A = 20, B = 32, and N = 5, then the output will be 22, 24, 26, 28, 30The task is simple we have to insert N number of elements in the Arithmetic Progression where A and B are the first and last term of that sequence. Suppose A1, A2, …. An are n arithmetic means. So the sequence will be A, A1, A2, …. An, B. So B is the (N + 2)th term of the sequence. ...

Read More

"Here" Documents in Perl

Mohd Mohtashim
Mohd Mohtashim
Updated on 11-Mar-2026 2K+ Views

You can store or print multiline text with great comfort. Even you can make use of variables inside the "here" document. Below is a simple syntax, check carefully there must be no space between the

Read More

Find smallest number K such that K % p = 0 and q % K = 0 in C++

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

Suppose we have two integers P and Q. We have to find smallest number K, such that K mod P = 0 and Q mod K = 0. Otherwise print -1. So if the P and Q are 2 and 8, then K will be 2. As 2 mod 2 = 0, and 8 mode 2 = 0.In order for K to be possible, Q must be divisible by P. So if P mod Q = 0 then print P otherwise print -1.Example#include using namespace std; int getMinK(int p, int q) {    if (q % p == 0)    return p;    return -1; } int main() {    int p = 24, q = 48;    cout

Read More

Find N Geometric Means between A and B using C++.

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

Suppose we have three integers A, B and N. We have to find N geometric means between A and B. If A = 2, B = 32, and N = 3, then the output will be 4, 8, 16The task is simple we have to insert N number of elements in the geometric Progression where A and B are the first and last term of that sequence. Suppose G1, G2, …. Gn are n geometric means. So the sequence will be A, G1, G2, …. Gn, B. So B is the (N + 2)th term of the sequence. So we ...

Read More
Showing 28531–28540 of 61,297 articles
Advertisements