Found 7197 Articles for C++

Maximum adjacent index difference for a subsequence T present in given string S

Shubham Vora
Updated on 24-Aug-2023 17:29:28

167 Views

In this problem, we need to find the maximum difference between the indices of the subsequence present in the given string. To solve the problem, we need to find the indices of the subsequence in the actual and reverse order. After that, we need to take the difference of both. Problem statement - We have given two strings named 'str' and 'sub'. The 'sub' string is always present in the 'str' string as a subsequence. We need to find the maximum index cost. The index cost is the difference between two indices of the subsequence. ... Read More

Maximize characters to be removed from string with given condition

Shubham Vora
Updated on 24-Aug-2023 17:25:16

152 Views

In this problem, we need to remove the maximum characters from the string if the adjacent character is the previous character. We can find the occurrence of each character and check whether any of its adjacent characters is a previous character, we can remove the particular character. Problem statement - We have given a string containing the N alphabetic characters. The given task is we need to remove the maximum number of characters, and we can remove any character of the string if any adjacent character is the previous character in the alphabet. At last, print the count ... Read More

Find the Suffix Array of given String with no repeating character

Shubham Vora
Updated on 24-Aug-2023 17:22:51

141 Views

In this problem, we will find the suffix array of the given string. We can sort all the string's suffixes using their first character, as the input string contains different characters. Problem statement - We have given a string containing the different alphabetical characters, and we need to find the suffix array of the given string. The suffix array of the string is a sorted array containing all suffixes of the given string. Sample examples Input str = "point"; Output 2 3 1 0 4 Explanation All suffixes of the string ... Read More

Find frequency of each digit 0-9 by concatenating ASCII values of given string

Shubham Vora
Updated on 24-Aug-2023 17:21:14

153 Views

In this problem, we need to count digits frequencies after merging the ASCII values of all characters. The approach to solving the problem is to create a string containing each character's ASCII values and count the frequency of the digits in the string. Problem statement - We have a string alpha containing different characters, and the length of the string is N. We need to calculate each digit's frequency after concatenating the ASCII values of the given string's characters. Sample examples Input alpha = "tutorialspoint" Output 4 25 1 0 1 3 3 2 1 1 ... Read More

Find all substrings with even 1s whose reverse is also present in given String

Shubham Vora
Updated on 24-Aug-2023 17:19:26

142 Views

In this problem, we need to prepare a set of unique substrings of the given binary string and remove them from the set if it contains an even number of 1s and its reverse also exits in the set. We can solve the problem using two ways. The first way is to find all substrings of the given binary string, check if any substring contains an even number of 1's and its reverse exits, and remove the reverse string from the set. Another way is by comparing the total number of parity bits in the given string. ... Read More

Encode Strings in form of “xAyB” where x and y and based on count of digits

Shubham Vora
Updated on 24-Aug-2023 17:17:50

103 Views

In this problem, we need to encode the string in xAyB format, where x is the count of digits present in both strings at the same index, and y is the count of digits in both strings at different indices. We can solve the problem by counting the same digits in both strings. Also, we can count the total number of the same digits present at same index in both strings to encode the string. Problem statement - We have given str1 and str2 strings of the same length containing only digits. We need to encode the given ... Read More

Encode given string by shifting each character forward with its alphabetical value

Shubham Vora
Updated on 24-Aug-2023 17:00:06

390 Views

In this problem, we need to calculate the distance between the character and 'a', and by adding it to the character, we need to shift the character. The solution approach is to find the difference between the ASCII values of both characters, and add it to the current character's ASCII value. Problem statement - We have given an alpha string of length N containing only alphabetical characters. We need to encode the string according to the below conditions. Take a distance between the current character and 'a'. ... Read More

Find Maximum Shortest Distance in Each Component of a Graph

Pranavnath
Updated on 25-Aug-2023 11:18:54

145 Views

Introduction In C language, finding the most extreme briefest separate in each component of a chart may be a vital assignment. The chart is spoken to utilizing a contiguousness list or lattice. By utilizing Breadth-First Search (BFS) or Depth-First Look (DFS), we will compute the most limited separations from each hub to all other hubs inside a component. To get the most extreme most brief separate in each component, we emphasize through the components and keep up a running most extreme. At last, we yield the comes about for each component. This productive calculation permits us to analyze complex systems, ... Read More

Count the number of nodes in a Graph whose sum of neighbours is at most K

Pranavnath
Updated on 25-Aug-2023 11:18:03

271 Views

Introduction Undirected graphs are an essential component of computer science and graph theory, representing a set of vertices connected by edges without any directionality. One common problem associated with undirected graphs is the counting the number of nodes in a graph whose sum of neighbours is at most K. In computer science, the graph theory field will deal with the connection between the elements in the given matrix. Usually the graphs consists of the elements namely the edges and the nodes. Count the number of nodes in a Graph The Graph that is exclusively used is the undirected graph in ... Read More

Difference between Minimum Spanning Tree and Shortest Path

Pranavnath
Updated on 25-Aug-2023 11:16:37

2K+ Views

Introduction The Minimum Spanning tree and the shortest tree plays a vital role in the field of graph theory to design the networks. While they share similarities as fundamental concepts, their purposes diverge significantly. In this article, we will dive into these two interesting elements within graphs and highlight their differences. MSTs aim at establishing minimal-cost connectivity among all vertices of a graph without loops, while shortest paths target identifying optimal routes between specific nodes in terms of distance or weight accumulation. Difference between Minimum Spanning Tree and shortest Path Graph theory offers various tools for analyzing connections and pathways ... Read More

Advertisements