Shubham Vora

Shubham Vora

793 Articles Published

Articles by Shubham Vora

Page 50 of 80

Modify array by removing characters from their Hexadecimal representations which are present in a given string

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 191 Views

We have given an array of positive integers and need to modify each element of the array by removing the characters given the ‘hex’ string from the hexadecimal representation of the current element. To solve the problem, we can convert the current number to a hexadecimal number. After that, we can remove the characters from the hexadecimal string, which are common in ‘hex’ and the current hexadecimal string. After modifying the hexadecimal string, we can convert it back to decimal. Problem statement – We have given an array containing positive integers, and the array's length is N. Also, we ...

Read More

Modify a Binary String by flipping characters such that any pair of indices consisting of 1s are neither co-prime nor divisible by each other

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 213 Views

In this problem, we have given a binary string of length 4*N, and we need to flip zeros of the binary string so that any pair of indices containing ‘1’ should not be co-prime or divisible by each other. Here, we can solve the problem by observation. The string contains 4*N characters. We can flip the N characters from the last, which are at the even index. Problem statement – We have given an integer N and a binary string of the length 4*N containing all zeros initially. We need to flip ‘0’ to ‘1’ in such a way so ...

Read More

Minimum time required to complete all tasks without altering their order

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 298 Views

In this problem, we need to find the total time required to complete all tasks according to the given condition. We can use the map data structure to solve the problem. We can keep tracking the last performed time for each task, and if the time interval is less than K, we can increment time units accordingly. Problem statement – We have given a string task containing alphabetical characters of length N. Each character represents a task, and we need one unit of time to perform the tasks. Also, the condition is that each task should be performed at ...

Read More

Minimum increments by 1 or K required to convert a string into another given string

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 493 Views

We have given two strings and need to convert one string to another by click increments, and we can increment characters by either 1 or k in the single operation. To solve the problem, we need to make all characters of the first string the same as a second character by performing the cyclic increment operations. If the character at the same index in both strings is the same, we don’t need to perform any increment operation. Problem statement – We have given two strings named first and second containing the uppercase alphabetical characters. The length of both strings ...

Read More

Lexicographically smallest string of maximum length made up of first K alphabets that does not contain any repeating substring

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 434 Views

In this problem, we need to generate a lexicographically smallest string using the first K characters of alphabets so that it doesn’t contain any repeated substring. We can generate a string so that all substrings of length 2 are unique. So, if all substrings of length 2 are unique, all substrings of length 3 or more are also unique. Problem statement – We have given a positive integer K. We need to generate a new string using the first K alphabets so that generated string can’t contain any repeated substring of length 2 or more and is lexicographically smallest. Sample ...

Read More

Find the last player to be able to remove a string from an array which is not already removed from other arrays

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 168 Views

In this problem, two players play a game by removing the string from their array, which is not already removed from the opponent's array. We need to decide the winner of the game. We can solve the problem using two different approaches. In the first approach, we can store the common strings with the set data structure. In the second approach, we can use a set to store already removed strings from both arrays. Problem statement – We have given two arrays called arr and brr. The size of the array is N and M, respectively. We need to decide ...

Read More

Count points which are revisited while following the path specified by a given string

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 143 Views

In this problem, we have given a string suggesting the moving direction and starting coordinates. We need to find the revisited positions. We can use the set or map data structure to store the previously visited coordinates. We can say that position is revisited if we find any pair in the set or map. Problem statement – We have given a string str of length N containing the ‘L’, ‘R’, ‘U’, and ‘D’ characters. Also, we have given X and Y integers representing the starting position. We need to find the total number of coordinates revisited while following the path ...

Read More

Count occurrences of substring X before every occurrence of substring Y in a given string

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 319 Views

In this problem, we need to count the total occurrences of the substring X in the str when we find the substring Y in the given string. We can keep counting the occurrences of the substring X, and when we get the substring Y, we can print the count value. Problem statement – We have given a string str, X, and Y. The length of the strings is N, A, and B, respectively. We need to total the total number of substring X in the given string str before every occurrence of the substring Y. Sample examples Inputstr = "stuxystuxy"; ...

Read More

class std::string_view in C++17

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 399 Views

C++ contains many precious features to enhance the performance of the code, and string_view class is one of them. It is introduced to create a lightweight and non-owning reference to a string. In this tutorial, we will discuss the string_view class and explore a few examples using the string_view class over the string class in C++. What is string_view? The string_view is a class in C++ that is used to create a read-only sequence of the string. It is a non-owning string type, meaning it does not manage the memory associated with the string and its reference. It acts as ...

Read More

Check if it is possible to obtain a Balanced Parenthesis by shifting brackets to either end at most K times

Shubham Vora
Shubham Vora
Updated on 18-Aug-2023 271 Views

In this problem, we need to check whether we can get the valid balanced subsequence of the parenthesis by moving at most K characters of the string at the end. To solve the problem, we can use the stack data structure. The logic to solve the problem is that if we find more than K ‘)’ (closing parenthesis) before the ‘(‘ (opening parenthesis), we can’t make a string into a valid subsequence. Problem statement – We have given string str containing the ‘(‘ and ‘)’ sequence of parenthesis. The length of the string is N. Also, We have given a ...

Read More
Showing 491–500 of 793 articles
« Prev 1 48 49 50 51 52 80 Next »
Advertisements