Found 7346 Articles for C++

How to validate ISIN using Regular Expressions?

Shubham Vora
Updated on 31-Aug-2023 10:05:54

466 Views

In this problem, we will use the regular expression to validate the ISIN number in C++. The ISIN stands for the International Securities Identification Number. It is a unique code to identify stocks, financial bonds, etc. The length of the ISIN number can be 12 or 14, which provides international recognization of the particular stuff. Let’s understand the format of the ISIN number. Country code − It starts with two characters of the country code. Identifier − It contains 9 alphanumeric characters after the country code. Checksum − It contains the single digit which is used to detect errors ... Read More

Find two unique Palindrome Strings using given String characters

Shubham Vora
Updated on 20-Oct-2023 15:00:47

99 Views

In this problem, we will construct two palindromic strings using the given string’s characters. We can use the character’s frequency to solve the problem. We can construct two new palindromic strings only if both characters’ frequencies are even or if any characters have an even frequency and others have an odd frequency. Problem statement − We have given a string alpha containing two different characters and a size equal to N. We need to construct two palindromic strings using the characters of the alpha, which are not the same as the given string alpha. Sample Examples After incrementing each character ... Read More

Find the final String by incrementing prefixes of given length

Shubham Vora
Updated on 31-Aug-2023 09:20:34

69 Views

In this problem, we need to increase each character of multiple prefixes of size given in the array. The naïve approach to solving the problem is to take each prefix of the size given in the array and increment each character of the prefix by 1. The best approach is to create the prefix array using the given array and update each string character in the single iteration. Problem statement − We have given a string alpha of length N. Also, we have given a prefixes array containing the positive integer. The prefixes[i] represent that take prefix of length prefixes[i] ... Read More

Count ways to select three indices from Binary String with different adjacent digits

Shubham Vora
Updated on 16-Oct-2023 17:35:07

75 Views

In this problem, we will find the number of pairs of 3 indices so that any adjacent indices don’t have the same value in the pair. We can get the output by checking each pair of 3 indexes, but it can be more time-consuming. Another approach to solving the problem is to take the current index and also take the index from left and right, which doesn’t contain a similar value to the current index's value. This way, we can count the total number of pairs each index can form and sum them to get the output. Problem statement − ... Read More

Count even indices of String whose prefix has prime number of distinct Characters

Shubham Vora
Updated on 16-Oct-2023 16:57:47

74 Views

In this problem, we will find total invalid characters in the given string. If total distinct characters till the particular even index is prime, we can say the character is invalid. We can use the map data structure to count the total number of distinct characters while traversing the string. Also, we can use the string of characters to keep track of the distinct digits. Also, for every character, we can check whether its index is even and whether distinct characters are prime. Problem statement – We have given a string alpha containing the N characters. We need to find ... Read More

Check if String can be divided into two Subsequences so that product of sum is odd

Shubham Vora
Updated on 16-Oct-2023 15:25:08

76 Views

In this problem, we will check if it is possible to divide the given numeric string into two disjoint subsequences such that sum(sub1) * sum(sub2) becomes odd. We need to divide the string into two subsequences such that the sum of the digits of both becomes odd to get the odd multiplication result. Problem statement − We have given a string num_string containing the numeric characters. We need to check whether we can divide the string into two subsequences such that the multiplication of the sum of both subsequences becomes odd. Also, it is given that every character of the ... Read More

Odd numbers in N-th row of Pascal’s Triangle

Rinish Patidar
Updated on 28-Aug-2023 20:52:29

137 Views

The problem statement includes counting the odd numbers in N−th row of Pascal’s triangle. A pascal’s triangle is a triangular array where each row represents the binomial coefficients in the expansion of binomial expression. The Pascal’s triangle is demonstrated as below: 1 1 ... Read More

Moser-de Bruijn Sequence

Rinish Patidar
Updated on 28-Aug-2023 20:51:30

113 Views

The problem statement includes printing the first N terms of the Moser−de Bruijn Sequence where N will be given in the user input. The Moser−de Bruijn sequence is a sequence consisting of integers which are nothing but the sum of the different powers of 4 i.e. 1, 4, 16, 64 and so on. The first few numbers of the sequence include 0, 1, 4, 5, 16, 17, 20, 21, 64....... The sequence always starts with zero followed by the sum of different powers of 4 such as $\mathrm{4^{0}}$ i.e $\mathrm{4^{1}\:i.e\:4, }$ then sum of $\mathrm{4^{0}\:and\:4^{1}\:i.e\:5}$ and so on. In this ... Read More

Vantieghems Theorem for Primality Test

Rinish Patidar
Updated on 28-Aug-2023 18:09:42

64 Views

The problem statement includes using Vantieghems theorem for primality test i.e. we will check for a positive number N which will be user input and print if the number is a prime number or not using the Vantieghems theorem. Vantieghem’s Theorem The Vantieghems theorem for primality states that a positive number, N is a prime number if the product of $\mathrm{2^{i}−1}$ where the value of i ranges from 1 to N−1 is congruent to N modulo $\mathrm{2^{N}−1}$ If both the values are congruent then the number N is a prime number else it is not a prime number. Congruent ... Read More

Sum of Range in a Series of First Odd then Even Natural Numbers

Rinish Patidar
Updated on 28-Aug-2023 17:59:41

86 Views

The problem statement includes finding the sum of range in a series of first odd numbers then even natural numbers up to N. The sequence consists of all the odd natural numbers from 1 to N and then all the even natural numbers from 2 to N, including N. The sequence will be of size N. We will be provided with a range in the problem for which we need to find out the sum of the sequence within that range, a and b i.e. [a, b]. Here a and b are included in the range. For example, we are ... Read More

Advertisements