Found 7346 Articles for C++

Sorting given Character Array using Linked List

Shubham Vora
Updated on 14-Aug-2023 13:32:25

152 Views

In this problem, we need to sort the given array of characters using a linked list. We can use bubble sort, selection sort, merger sort, etc. techniques to sort the array. Here, we will convert the array into the linked list first and then use the selection sort and bubble sort techniques to sort the array. Problem statement − We have given an array arr[] of length N. The array contains lowercase alphabetical characters. We need to sort the array using the linked list. Sample examples Input arr[] = {'e', 's', 'a', 'x', 'c', 'e', 'f', 'p', 'b', 'n', ... Read More

Python3 Program for Minimum Rotations Required to get the Same String

Shubham Vora
Updated on 14-Aug-2023 13:28:47

52 Views

In this problem, we need to find the total number of rotations to get the same string. The naïve approach to solving the problem is that we can keep rotating the string. We can print the total number of required rotations if we find the same string. Also, other approaches take the substring from the string and make it equal to the original string. After that, we can get rotations using the substring length. Problem statement − We have given string str. We need to find the total number of rotations required to get the same string again. Sample examples ... Read More

Python Program for Generating Lyndon Words of Length n

Shubham Vora
Updated on 14-Aug-2023 13:27:24

58 Views

In this problem, we will find all Lyndon words using the array's alphanumeric characters. Before we start, let’s understand the definition of the Lyndon word. All words are Lyndon words which are strictly lexicographically smaller than all of their rotations. Here are examples of Lyndon words. ab − The ‘ab’ is strictly lexicographically smaller than all of its permutations which is ‘ba’. 89 − The rotations of ‘89’ is ‘98’, which is strictly lexicographically larger than ‘89’. abc − The rotations of ‘abc’ are ‘bca’ and ‘cab’, which are strictly greater than ‘abc’. Here ... Read More

PHP Program for Minimum Rotations Required to get the Same String

Shubham Vora
Updated on 14-Aug-2023 13:26:07

49 Views

In this problem, we need to achieve the same string by performing the rotations of the string and need to count rotations. There can be different ways to solve the problem, but here we will learn some best approaches in PHP. The first approach uses the rotational substring, and another approach divides the string into two parts from the particular index. Problem statement − We have a string str containing n characters. We have to find the minimum rotations of string we should perform to achieve the same string again. Sample examples Input str = "bcbc"; Output ... Read More

Minimize Replacement of Bits to make the Count of 01 Substring Equal to 10 Substring

Shubham Vora
Updated on 14-Aug-2023 13:23:50

70 Views

Problem statement − We have given the binary string of length N. We need to find the minimum number of flipping characters required to get the balanced binary string. Flipping characters means converting 0 to 1 and 1 to 0. If any string contains an equal number of ‘01’ and ‘10’ pairs, we can say that string is a balanced binary string. Sample examples Input str = "001010" Output 0 Explanation − The string contains 2 ‘01’ and ‘10’ pairs. So, we don’t need to perform any flipping operations. Input str = ‘00001’ ... Read More

Javascript Program to Check If a String is Substring of Another

Shubham Vora
Updated on 14-Aug-2023 13:22:10

160 Views

In this problem, we need to ensure whether the string String2 contains string String1 as a substring. We will first see the naïve approach to solving the problem, finding all substrings of String1’s length in String2 with String1. Furthermore, we will use built−in methods like match(), includes(), and indexOf() methods to find the String1 substring in the String2. Problem statement − We have given a string String1 and String2 of different sizes. We need to check whether string String1 is present in string String2 as a substring. Sample examples Input string1 = "tutor"; string2 = "pointtutorial"; Output ... Read More

Java Program to Recursively Remove All Adjacent Duplicates

Shubham Vora
Updated on 14-Aug-2023 13:16:22

377 Views

We need to remove all adjacent duplicate characters from the string in this problem. We can use a recursive or iterative approach to solve the problem. Here, we first need to remove the adjacent duplicate elements from the left part of the string. After that, we need to recursively remove the adjacent duplicates from the right part of the string. Problem statement − We have given string str of length N containing alphanumeric characters. We need to recursively remove all adjacent duplicate characters so that the resultant string does not contain any adjacent duplicate characters. Sample examples Input str1 ... Read More

Java Program for Minimum Rotations Required to Get the same String

Shubham Vora
Updated on 14-Aug-2023 13:10:19

163 Views

In this tutorial, we need to write a Java program to count the total number of minimum required rotations to get the original string. We can solve the problem by getting the rotations substrings of the original string or concatenating the original string to itself. Problem statement − We have given string str of length N. The task is to find the total number of minimum rotations we need to perform to get the original string. Sample examples Input str = "bcdbcd"; Output 3 Explanation − We need to make 3 rotations to get the ... Read More

Java Program for Minimum Move to end Operations to Make all Strings Equal

Shubham Vora
Updated on 14-Aug-2023 13:05:47

98 Views

In this problem, we have given n strings and need to make all strings equal by rotating them. To solve the problem, we need to pick any string from the array and need make all strings equal by rotating them. Also, we need to count the total number of required operations to rotate all strings. We can pick each string one by one, make all other strings equal, count the total operations for each string, and take a minimum of them. Problem statement − We have given an array containing n strings. All strings are permutations of each other. ... Read More

Generate String after Adding Spaces at Specific Positions in a given String

Shubham Vora
Updated on 14-Aug-2023 13:03:58

107 Views

In this problem, we need to add spaces before the given indexes in the string. We can use two different approaches to solve the problem. The first approach moves the characters of the given string to add space at a particular index, and the second approach replaces the characters of the pre−initialize string with spaces. Problem statement − We have given string str of length N containing the alphanumeric characters. Also, we have given the spaceList array containing M positive integers representing the string index. We need to app space to the string before each index that exists in the ... Read More

Advertisements