Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 41 of 80

Print Words with Prime length from a Sentence

Shubham Vora
Shubham Vora
Updated on 27-Oct-2023 791 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

Minimum deletion such that XOR of adjacent digits is atmost 1

Shubham Vora
Shubham Vora
Updated on 27-Oct-2023 219 Views

In this problem, we will learn to find the count of minimum deletion required so that when we take the XOR of any two adjacent elements, we should either get 0 or 1. We will use the properties of the XOR operations to solve the problem. For example, when we take XOR of the same numbers, we always get 0; when we take XOR of the consecutive even and odd number, we get 1. Problem Statement We have given a num_str string containing the numeric digits. We need to count the minimum deletions required so that the XOR ...

Read More

Minimize operations to make String palindrome by incrementing prefix by 1

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 336 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

Maximum moves to reach destination character in a cyclic String

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 222 Views

In this problem, we will find the maximum distance from the initial to the final character in the cyclic string. The basic approach to solve the problem is to find the next closest final character for every initial character and update the maximum distance if required. Another approach traverses the string in reverse order and keeps track the index of the last final character. When we get an initial character, we measure the distance and update the maximum distance if required. Problem statement − We have given an str string containing the 3 characters, and the length equals N. Also, ...

Read More

Maximize value of Binary String in K steps by performing XOR of Substrings

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 540 Views

In this problem, we will maximize the value of the binary string by performing K XOR operations of substrings of the given binary string. To maximize any binary string, we should maximize the substring starting from the leftmost zero. For example, to maximize the ‘11001’ string, we need to choose another substring in such a way that we can maximize the ‘001’ substring. Problem Statement We have given a binary string named bin_str containing N characters. We have to maximize the value of the binary string in K operations by taking the XOR operation of any two substrings. It ...

Read More

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

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 173 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

Maximize “10” Subsequences by replacing at most one 0 with 1

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 251 Views

In this problem, we need to maximize the ‘10’ subsequences in the given binary string by replacing the 0 or 1 ‘0’ character with ‘1’. We can replace each ‘0’ with ‘1’ one after another and find a maximum number of ‘10’ subsequences in the updated string. Problem statement − We have given a binary string named str1 containing only 0 and 1 characters. We can replace at most one ‘0’ with ‘1’ and need to find the maximum number of ‘10’ subsequences in the given string. Sample Examples Input  str1 = "10110" Output  4 Explanation The ‘10110’ ...

Read More

Make all Strings palindrome by swapping characters from adjacent Strings

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 869 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

Longest Substring of A that can be changed to Substring of B in at most T cost

Shubham Vora
Shubham Vora
Updated on 23-Oct-2023 306 Views

In this problem, we will find the longest substring of A to convert it to a substring of B starting from the same index in less than T cost. We will use the binary search algorithm to find the maximum length of the substring which follows the given condition. However, the naïve approach to solving the problem is to find all substrings following the conditions in the problem statement and take the substring with maximum length. Problem statement − We have given a string A and B of length N. Also, we have given a total cost, ‘T’. The ...

Read More

Find two unique Palindrome Strings using given String characters

Shubham Vora
Shubham Vora
Updated on 20-Oct-2023 236 Views

In this problem, we will construct two palindromic strings using the given string’s characters. We can use the character’s frequency to solve the problem. We can construct two new palindromic strings only if both characters’ frequencies are even or if any characters have an even frequency and others have an odd frequency. Problem statement − We have given a string alpha containing two different characters and a size equal to N. We need to construct two palindromic strings using the characters of the alpha, which are not the same as the given string alpha. Sample Examples After incrementing each character ...

Read More
Showing 401–410 of 793 articles
« Prev 1 39 40 41 42 43 80 Next »
Advertisements