Found 7346 Articles for C++

Check if a string represents a hexadecimal number or not

Siva Sai
Updated on 16-Oct-2023 14:53:15

3K+ Views

In computer science, hexadecimal is a base-16 number system. It uses 16 distinct symbols, including the ten decimal digits from 0 to 9 and the six letters A, B, C, D, E, and F to represent numbers from 0 to 15. In this article, we will discuss how to check if a string represents a hexadecimal number or not. Problem Statement Given a string, the task is to check if it represents a valid hexadecimal number or not. Approach We can solve this problem by iterating over the characters in the string and checking if they belong to the set ... Read More

Check if a string can be split into two substrings with equal number of vowels

Siva Sai
Updated on 16-Oct-2023 14:16:58

265 Views

Welcome to another in-depth guide on a fascinating problem-solving topic in C++. This time, we will be tackling the problem of determining if a string can be divided into two substrings, each containing an equal number of vowels. This problem is an excellent exercise for honing your skills in string manipulation and vowel counting. Problem Statement Given a string, our objective is to determine if it can be partitioned into two non-empty substrings such that both substrings have an equal number of vowels. The vowels in the English alphabet are 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'. ... Read More

Check if a sequence of path visits any coordinate twice or not

Siva Sai
Updated on 16-Oct-2023 16:21:38

77 Views

In certain applications, we might be interested in checking whether a sequence of path visits any coordinate twice or not. This can be useful, for example, in GPS tracking systems to detect if a vehicle is going back and forth between two points. In this article, we will discuss how to check if a sequence of path visits any coordinate twice or not, along with its implementation in C++. Algorithm To solve this problem, we can use a hash table to keep track of all the coordinates that we have visited so far. We start by visiting the first coordinate ... Read More

Maximize partitions in a given Binary String having the same ratio of 0s and 1s

Prabhdeep Singh
Updated on 17-May-2023 14:57:36

85 Views

A binary string is a string that contains only zeros and ones as the different types of characters. We have given a binary string and the task is to divide it into some number of partitions (possibly zero) where each partition contains an equal ratio of zero and one. We will use the hashmap to solve the problem with efficient time and space complexity. Sample Examples Input 1: string str = 100010001 Output: 3 Explanation The given string can be partitioned into three substrings that will contain the same ratio of zeros and ones. We can break the string into ... Read More

Maximum Occurring Character in a Linked List

Prabhdeep Singh
Updated on 17-May-2023 14:54:23

224 Views

We have given a singly linked list of characters, and our task is to print the character which occurs the maximum time in the linked list. If the multiple characters have the same count of occurring then print the character which comes in the last. The Singly-linked list is a linear data structure that consists of nodes. Each node contains the data and the pointer to the next node which contains the memory address of the next node because the memory assigned to each node is not continuous. Sample Examples Let us assume we have given a linked list of ... Read More

Check if the summation of two words is equal to the target word

Prabhdeep Singh
Updated on 17-May-2023 14:52:42

58 Views

We will be given three strings str1, str2, and str3 in this problem of the same or different lengths and we have to find whether the sum of the first two strings is equal to the third or not. Each of the strings contains elements less than ‘k’ which means ‘a’ can be decoded as ‘0’ and j as ‘9’ and we can take the sum of them as the normal numbers. Sample Examples Input 1 string str1 = “abc” string str2 = “bbe” string str3 = “cdg” Output: Yes Explanation − We can decode ‘a’ as ‘0’, ‘b’ as ... Read More

Lexicographically smallest string formed repeatedly deleting a character from substring ‘10’

Prabhdeep Singh
Updated on 17-May-2023 14:45:51

347 Views

Lexicographically smallest string means among the set of strings is the string which appears first in the dictionary order is known as a lexicographically smallest string. We will be given a binary string (that contains only two different types of characters 0 and 1) and we can delete character ‘1’ from any substring ‘10’ from the given string at any number or time. We have to create the lexicographic string by applying this method. Sample Examples Input 1 string str = “1101010011” Output: 000011 Explanation − As we can only remove the character ‘1’ so will remove all the ones ... Read More

Maximum Pairs of Bracket Sequences which can be concatenated to form a Regular Bracket Sequence

Prabhdeep Singh
Updated on 17-May-2023 14:44:06

150 Views

Regular Bracket Sequence means a string that contains the parentheses of both opening and closing types and results in properly closed brackets. The given sequence may be properly symmetrical and maybe not. In this problem, we are given a list of string that contains the bracket sequences and we have to find the number of pairs that can be concatenated to a single regular bracket sequence. Sample Examples Input 1 string arr[] = {“)()”, “()(“, “()()”, “(())”} Output: 2 Explanation − For the first and second strings we can concatenate the first string after the second string resulting in the ... Read More

Maximum count of 0s between two 1s in the given range for Q queries

Prabhdeep Singh
Updated on 17-May-2023 14:41:15

159 Views

A binary string is a string that only contains the zeroes and ones as the different characters in them. We are given a binary string and an array of a given length that will contain the pairs. Each pair defines the range, and in that range, we have to return the maximum number of zeros lying between two ones. We will implement two approaches one is the naive approach and another is the efficient approach. Let’s understand with the help of example Input String str = ‘1011010110’ Array Q[][] = {{0, 2}, {2, 5}, {0, 9}} Output: 1 1 3 ... Read More

Minimum cost for constructing the subsequence of length K from given string S

Prabhdeep Singh
Updated on 17-May-2023 14:39:01

155 Views

We will be given a string of length n, an integer k, and an integer array of length 26. The integer array defines the cost of each lowercase character and the string will contain only lowercase letters. We have to create a subsequence of length k from the given string at the minimum possible cost. We will use sorting to solve the problem and will implement a code with a full explanation. Sample Examples Input 1 Given string: acbcbac Given number: 4 Given array: {2, 3, 1, 2, 4, 5, 5, 6, 6, 2, 1, 0, 4, 3, 5, ... Read More

Advertisements