Found 7346 Articles for C++

Count of 3 sized Strings of all same or different characters using total X 0s, Y 1s and Z 2s

Shubham Vora
Updated on 24-Aug-2023 16:34:30

43 Views

In this problem, we will count the number of strings we can create using the given frequencies such that the string contains same or different characters. We have four options to create a string of length 3 using the 0, 1, and 2 characters. The first string is 012, 000, 111, and 222. So, we need to count the total number of such strings to get the answer. Problem statement – We have given three integer values: X, Y, and Z. The X represents the frequency of the ‘0’, Y represents the frequency of the ‘1’, and Z represents the ... Read More

Convert characters of string1 to characters present in string2 by incrementing or decrementing lexicographically

Shubham Vora
Updated on 24-Aug-2023 16:31:03

52 Views

In this problem, programmers require to make all characters of str1 equal to any character of str2 by performing the increment or decrement operation. Also, we can increment or decrement rotationally. It means ‘z’ + 1 ==‘a’ and ‘a’ – 1 == ‘z’. We can solve the problem by finding the minimum cost of making the str1 string’s character equal to any character of the string str2. For each character, we can find the minimum required operations and sum them all. Problem statement – We have given two strings named str1 and str2. The size of the str1 is ... Read More

Maximize product of array by replacing array elements with its sum or product with element from another array

Prabhdeep Singh
Updated on 24-Aug-2023 14:26:07

102 Views

We are given two arrays of the same length and we have to apply some operations to get the product of the first array with all elements maximum. The operations are to multiply or add any element of the second array only once to any element of the first array only once. We can add or multiply two different elements from the second array element to a single first array element. After all operations, we have to take the product of all the elements of the first array and return that. Example Let's understand the problem with the help of ... Read More

C++ Program to Find Maximum number of 0s placed consecutively at the start and end in any rotation of a Binary String

Shubham Vora
Updated on 24-Aug-2023 16:29:34

78 Views

In this problem, we need to find the maximum consecutive zeros at the start and end of string rotation. We can follow two approaches to solve the problem. The first approach is to find all rotations of the given string and count start and end zeros. The second approach is to count the maximum consecutive zeros in the string and get the answer. Problem statement – We have given the binary string named str of size equal to ‘len’. We need to count the maximum number of consecutive zeros at the start and end of any rotation of the string. ... Read More

C++ Program for Queries for rotation and Kth character of the given string in constant time

Shubham Vora
Updated on 24-Aug-2023 16:22:24

64 Views

In this problem, we need to perform the given queries on the string. We can solve the problem by making the rotations of the string differently and accessing the required characters using their index. Problem statement – We have given string str of length N and array ‘que’ of size M containing queries. We need to perform the queries given in the array according to the below conditions. (1, x) – Make x left rotations of the string. (2, x) – Show the xth character in the output. Sample examples Input que[][2] = {{1, 2}, {2, 1}, ... Read More

Difference between Queue and Deque in C++

Prabhdeep Singh
Updated on 24-Aug-2023 14:24:13

705 Views

Queue and Deque both are linear data structures that are defined in STL of C++ programming language. Queue works on the principle of the first in first out, the element added to the queue first will be removed first, on the other hand, deque has properties to add an element either at the first index or last index, and similarly, any one of them can be removed. We will see the code of both data structures to get the exact differences. Basics of Queue As we have seen above, the queue is based on the concept of the first in ... Read More

Check whether a Sentence is Tautogram or Not

Shubham Vora
Updated on 24-Aug-2023 16:19:24

49 Views

In this problem, we need to check whether the given sentence is tautogramic. We can say any sentence is tautogramic if all words have the same starting character. We will learn two approaches to solving the problem. The logic to solve the problem is to check all words' first characters. If any word has a mismatched first character, we can say the sentence is not tautogramic. Problem statement – We have a string containing the N characters. We need to check whether the given string is tautogramic or not. Note – The tautogramic contains all words starting with the same ... Read More

Distance of each node of a Binary Tree from the root node using BFS

Prabhdeep Singh
Updated on 24-Aug-2023 14:21:07

83 Views

Binary Tree is a non-linear data structure. It has a maximum of two children and each node contain three things that are data value, left and right pointer. The top node is called the root node and the last node which does contain any children is called the leave node. In this problem, we have given a binary tree. It has N nodes in the range from 1 to N (both inclusive) and our task is to find the distance of each node of a binary tree from the root node using BFS. Examples Let's see examples with explanations below ... Read More

Find the Largest and smallest number in an Array containing small as well as large numbers

Prabhdeep Singh
Updated on 24-Aug-2023 14:19:04

85 Views

We are given an array of strings and each string represents a number that could be more than the range of the maximum integer limit. We have to find the largest and the smallest element from the given array. We cannot use the simple less than or greater than operators to check which string is greater as it won't works find with the string so we will make our own comparison function. Example Let's understand the problem with the help of an example − Input string arr[] = {"2", "3", "12", "23", "22", "0", "7"} Output The smallest element ... Read More

Longest Substring containing C2, starting with C1 and ending with C3

Prabhdeep Singh
Updated on 24-Aug-2023 14:17:12

38 Views

A substring is a string that can be achieved from the given string by removing some characters from the beginning and end of the string (possibly none or all). We are given a string and three characters and have to find the longest substring that contains all the three given characters in the sequence of c1, c2, and c3 starting with c1 and ending with c3. Also, the given characters may be the same but we string must contain different characters for each of them. Input string str = "abacdeab" char c1 = a char c2 = b char ... Read More

Advertisements