Found 7346 Articles for C++

Count M-length substrings occurring exactly K times in a string

Siva Sai
Updated on 16-Oct-2023 17:01:29

252 Views

In this article, we will be delving into a unique and fascinating problem from the realm of computer science - "Counting M-Length Substrings Occurring Exactly K Times in a String". This type of problem is often encountered during programming competitions and interviews. Before we get started, let's define what we're dealing with − Substrin − A continuous sequence that is found within another string. M-Length − The length of the substring that we're interested in. K Times − The exact number of times the substring should appear in the original string. Algorithm Explanation To solve this problem, we will leverage the ... Read More

Count distinct regular bracket sequences which are not N periodic

Siva Sai
Updated on 16-Oct-2023 16:52:06

235 Views

In this article, we're going to delve into an intriguing problem from the realm of combinatorics and string processing: "Counting distinct regular bracket sequences which are not N periodic". This problem involves generating distinct valid bracket sequences and then filtering out sequences that are N-periodic. We'll discuss the problem, provide a C++ code implementation of a brute-force approach, and explain a test case. Understanding the Problem Statement Given an integer N, the task is to count the distinct regular bracket sequences of length 2N which are not N-periodic. A sequence is N-periodic if it can be represented as a string ... Read More

Count anagrams having first character as a consonant and no pair of consonants or vowels placed adjacently

Siva Sai
Updated on 16-Oct-2023 16:28:28

89 Views

Anagrams are a fascinating concept in computer science and language processing. They are essentially words or phrases made by rearranging the letters of another word or phrase. The challenge increases when we introduce specific rules. Today, we'll delve into a unique problem - counting anagrams that start with a consonant and have no adjacent consonants or vowels. We'll use C++ to develop a solution and walk through an illustrative example. Algorithm Explanation Our task is to count anagrams under two constraints − The first character must be a consonant. There should be no adjacent consonants or vowels. To ... Read More

Classify strings from an array using Custom Hash Function

Siva Sai
Updated on 17-May-2023 15:37:45

248 Views

In this article, we will delve into an interesting problem involving strings, hashing, and classification in C++. The problem statement is "Classify strings from an array using a custom hash function". This problem offers a great opportunity to learn about custom hash functions, their uses, and their applications in data classification and string manipulation. Problem Statement Given an array of strings, the task is to classify the strings into different categories using a custom hash function. Custom Hash Function A hash function is a function that is used to map data of arbitrary size to a fixed size. In our ... Read More

Check if two binary strings can be made equal by swapping 1s occurring before 0s

Siva Sai
Updated on 16-Oct-2023 16:17:53

243 Views

In this article, we will be discussing an intriguing problem related to string manipulation and binary numbers in C++. The problem we will be tackling is "Check if two binary strings can be made equal by swapping 1s occurring before 0s". This problem is a great way to enhance your understanding of strings, binary numbers, and algorithmic thinking. Problem Statement The task is to determine if two binary strings can be made equal by swapping 1s that occur before 0s in the strings. C++ Solution Approach The approach to solve this problem is to keep track of the number of ... Read More

Check if substrings from three given strings can be concatenated to form a palindrome

Siva Sai
Updated on 16-Oct-2023 15:38:05

146 Views

Palindromes are a fascinating topic in computer science and programming. A palindrome is a word, phrase, number, or other sequences of characters that read the same forward and backward, ignoring spaces, punctuation, and capitalization. In this article, we will investigate a unique problem: how to determine if substrings from three given strings can be concatenated to form a palindrome. This problem is a common interview question and can be solved using various techniques, including string manipulation, hashing, and dynamic programming. Problem Statement Given three strings, the task is to check if it's possible to select substrings from each of the ... Read More

Check if given number contains only “01” and “10” as substring in its binary representation

Siva Sai
Updated on 16-Oct-2023 15:20:35

159 Views

In this article, we delve into an interesting problem from the world of binary string manipulation: "Check if a given number contains only '01' and '10' as substrings in its binary representation". This problem challenges us to verify whether a number's binary representation contains only the substrings '01' and '10'. We'll discuss the problem in detail, offer a C++ code implementation, and illustrate the concept with an example. Understanding the Problem Statement Given a number, the task is to check if its binary representation contains only '01' and '10' as substrings. In other words, we need to verify if the ... Read More

Check if characters of each word can be rearranged to form an Arithmetic Progression (AP)

Siva Sai
Updated on 16-Oct-2023 15:16:26

85 Views

In this article, we will discuss how to check if the characters of each word in a given string can be rearranged to form an Arithmetic Progression (AP). We will also implement the solution in C++ and provide an example to illustrate the working of the code. Arithmetic Progression (AP) An Arithmetic Progression (AP) is a sequence of numbers in which each term after the first is obtained by adding a constant d to the preceding term. The constant d is called the common difference. For example, the sequence 1, 3, 5, 7, 9 is an Arithmetic Progression with common ... Read More

Check if characters of a string can be made non-decreasing by replacing ‘_’s

Siva Sai
Updated on 16-Oct-2023 15:12:17

160 Views

In this article, we'll delve into an intriguing problem in the field of string manipulation: how to check if the characters of a given string can be made non-decreasing by replacing '?' characters. This problem provides an excellent opportunity to hone your skills in string manipulation and condition checking in C++. Problem Statement Given a string consisting of alphabetic characters and question marks (?), determine whether the characters can be made non-decreasing by replacing the '?'s. The non-decreasing condition means that for every two adjacent characters in the string, the ASCII value of the second character is not less than ... Read More

Check if all strings of an array can be made same by interchanging characters

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

85 Views

In this article, we will explore the problem of checking whether all strings of an array can be made the same by interchanging characters. We will first understand the problem statement and then investigate both the naive and efficient approaches to solve this problem, along with their respective algorithms and time complexities. Lastly, we will implement the solution in C++. Problem Statement Given an array of strings, determine if all strings can be made the same by interchanging characters. Naive Approach The naive approach is to sort the characters of each string in the array and then compare each sorted ... Read More

Advertisements