Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 16 of 80

Check if substring S1 appear after any occurrence of substring S2 in given sentence

Shubham Vora
Shubham Vora
Updated on 17-Aug-2023 459 Views

In this problem, we need th check whether the substring S1 appears after any occurrence of the substring S2 in the given string S. We can compare the starting index of S1 and S2 in the string S to solve the problem. Problem statement – We have given three substrings named S, S1, and S2. The string S always contains S1 as a substring. We need to check whether the substring S1 appears after any occurrence of the substring S2 in the given string S. Sample examples Input – S = "abxtutorialspointwelcomepoint", S1 = "welcome", S2 = "point"; ...

Read More

Check if any permutation of a given string is lexicographically larger than the other given string

Shubham Vora
Shubham Vora
Updated on 17-Aug-2023 230 Views

We have given two strings and need to check whether the given string's permutations exist such that one permutation can have a larger character than another permutation at the ith index. We can solve the problem by sorting the string and comparing each character of the string one by one. Also, we can solve the problem using the frequency of characters of both strings. Problem statement – We have given a string str1 and str2 of length N. We need to check whether any permutations of both strings exist such that the permutation of one string is lexicographically larger than ...

Read More

C++ Program for Longest subsequence of a number having same left and right rotation

Shubham Vora
Shubham Vora
Updated on 17-Aug-2023 188 Views

In this problem, we need to find the maximum length of the sub sequence with the same left and right rotations. The left rotation means moving all characters of the string in the left direction and the first character at the end. The right rotation means moving all string characters in the right direction and the last character at the start. Problem statement – We have given string str containing numeric digits and need to find the sub sequence of maximum length with the same left and right rotations. Sample examples Input – str = "323232", Output – 6 Explanation– ...

Read More

Average value of set bit count in given Binary string after performing all possible choices of K operations

Shubham Vora
Shubham Vora
Updated on 17-Aug-2023 167 Views

In this problem, we need to find the average value of the count of set bits after performing K operations of all choices on the given string. There can be a brute force approach to solve the problem, but we will use the probability principles to overcome the time complexity of the brute force approach. Problem statement – We have given an integer N, array arr[] containing K positive integers, and a binary string of length N containing only set bits. We need to find the average value of the count of set bits after performing all possible choices ...

Read More

Check if the String has a Reversible Equal Substring at the Ends

Shubham Vora
Shubham Vora
Updated on 14-Aug-2023 165 Views

In this problem, we need to find the reversible equal substring of maximum length from the start and end of the string. The problem is very similar to finding the palindromic string. We can start traversing the string and traverse the string until characters from the start and end match. Problem statement − We have given string str containing N characters. We need to check whether the string contains the reversible equal substring at the start and end of the string. If we find the substring according to the given condition, print the longest substring. Otherwise, print ‘false’ in the ...

Read More

Abbreviate given String by Replacing all Characters with Length Except the First and Last

Shubham Vora
Shubham Vora
Updated on 14-Aug-2023 259 Views

In this problem, we need to transform the string of a length greater than 2 into its abbreviation form. We can use the ‘length’ property of the string to count the total number of middle characters in the string, and we can first and last characters using the respected index value. Problem statement − We have given a string str of length greater than or equal to 2 and need to convert the string into its abbreviation form. The abbreviation form of the string is as shown here: first character + the total number of middle characters + last ...

Read More

Sorting given Character Array using Linked List

Shubham Vora
Shubham Vora
Updated on 14-Aug-2023 369 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

Python Program for Generating Lyndon Words of Length n

Shubham Vora
Shubham Vora
Updated on 14-Aug-2023 209 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
Shubham Vora
Updated on 14-Aug-2023 154 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
Shubham Vora
Updated on 14-Aug-2023 278 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
Showing 151–160 of 793 articles
« Prev 1 14 15 16 17 18 80 Next »
Advertisements