Found 2620 Articles for Java

Flip the String by Either Swapping given Characters or Rotating it Horizontally for Q Queries

Aishwarya Mani Tripathi
Updated on 20-Oct-2023 15:09:31

62 Views

Flip the String by either swapping given characters or rotating it horizontally for Q queries is a fascinating problem that involves manipulating a string based on a series of queries. In this tutorial, we delve into this problem and provide a solution using C++. The problem statement revolves around a string of characters and a set of queries, each containing instructions to swap specific characters or perform a horizontal rotation. Our objective is to determine the final configuration of the string after applying all the queries. Through this tutorial, we will explore the intricacies of the ... Read More

Flip all 0s in given Binary Strings K times with different Neighbours

Aishwarya Mani Tripathi
Updated on 20-Oct-2023 15:04:36

81 Views

The task of flipping 0s in a binary string while considering their adjacent characters has practical applications in various domains. In this tutorial, we delve into the problem of modifying a given binary string by repeatedly flipping the 0s that have different adjacent characters. Specifically, we aim to solve this problem within the context of C++ programming. The solution involves iteratively scanning the string and applying the necessary flips based on the provided logic. By leveraging the string manipulation capabilities, we can efficiently transform the binary string by flipping 0s K times, ensuring that each flip adheres to the ... Read More

Validating Indian vehicle number plate using Regular Expression

Shubham Vora
Updated on 27-Oct-2023 16:21:40

959 Views

In this problem, we will validate the Indian vehicle number plate using the regular expression. The regular expression is the search pattern created using the different characters, which we can use to match a particular pattern in the given string. Problem statement - We have given a string representing the Indian vehicle number plate. We need to use the regular expression to validate the given string. Sample Example Input: num1 = "GJ 03 AY 1097" Output: Yes Explanation - The given vehicle number plate is valid. Input: num2 = "TN 1A3 PZ 1287" ... Read More

Print Words with Prime length from a Sentence

Shubham Vora
Updated on 27-Oct-2023 15:24:33

162 Views

In this problem, we need to show all words of the string having the prime length. The logical part of the problem is getting the words from the string and checking whether its length is prime. We can check whether the length of the number is divisible by any number to ensure whether it is a prime number. Also, we will use the sieve of Eratosthenes and the wheel factorization algorithm to check whether the word length is a prime number. Problem statement − We have given a string alpha, and we need to print all words of ... Read More

Minimize operations to make String palindrome by incrementing prefix by 1

Shubham Vora
Updated on 23-Oct-2023 16:10:04

84 Views

In this problem, we will count the number of operations required by increasing the prefix characters of the given string. We will use character difference to count the minimum number of operations required to make string palindromic. Problem Statement We have given a string nums containing the numeric digits. We need to count a minimum number of operations required to convert a string into the palindrome. In one operation, we can select any prefix of the string and increment all prefix characters by 1. Sample Example Input nums = "22434" Output 2 Explanation ... Read More

Maximize sum by picking Array element to left of each ‘1’ of a Binary String

Shubham Vora
Updated on 23-Oct-2023 15:03:43

61 Views

In this problem, we will find the maximum sum of array elements by picking up unselected elements at the left from the current 1's index. We can use the vector list and sort() method to solve the problem or priority queue. The priority queue inserts the element in the sorted order. Problem Statement We have given a binary string alpha and arr[] of the same length. We need to pick all '1' of alpha one by one and take the maximum element which is not picked from the subarray of arr[] formed using 0 to p elements. Here, ... Read More

Make all Strings palindrome by swapping characters from adjacent Strings

Shubham Vora
Updated on 23-Oct-2023 14:54:49

287 Views

In this problem, we will make all strings of the given array palindromic by swapping the characters of the adjacent string. To solve the problem, we will try to make the character the same at p and str_len - p - 1 index in all strings, and it is only possible if overall characters at pth index and (str_len - p - 1) index is same. Problem statement - We have given an arr containing multiple strings of the same length equal to N. We need to count the minimum number of operations required to make all strings of ... Read More

Find Strings formed by replacing prefixes of given String with given characters

Shubham Vora
Updated on 20-Oct-2023 14:45:29

54 Views

In this problem, we will form a triangle from the given string. The triangle will contain the rows equal to the string length - 1, and in each row, we replace the starting characters equal to the row number with '.' Character. We can use the loop to form each row of the string or string constructor and substr() method. Problem statement - We have given a string alpha. We need to print the string in the triangle pattern. We need to start the triangle with the alpha string and replace the first character of the previous string ... Read More

Count Substrings with even frequency of each character and one exception

Shubham Vora
Updated on 16-Oct-2023 17:27:46

102 Views

In this problem, we will count the number of substrings of the given string containing all characters with even frequency or any single character with odd frequency. We will use the bitmasking technique to solve the problem. In bitmasking, each bit of the binary string represents the character. Problem Statement We have given a string alpha of length N. It is also given that 'a'

Split Parenthesis Sequence into maximum valid Substrings

Shubham Vora
Updated on 27-Oct-2023 16:07:31

70 Views

In this problem, we need to split the parenthesis string into valid groups. When all opening brackets have related closing brackets, we can say that the group of parenthesis is valid. Problem Statement We have given a string containing open and closed parentheses. We need to split the string to get the maximum valid parenthesis string. Sample Examples Input: par = "(())()(()())" Output: (()), (), (()()), Explanation Each substring contains the valid parentheses sequence. Input: par = "()()" Output: (), () Explanation We have splited the string into two groups. Input: ... Read More

Previous 1 ... 5 6 7 8 9 ... 262 Next
Advertisements