Encode String by Shifting Each Character Forward

Shubham Vora
Updated on 24-Aug-2023 17:00:06

403 Views

In this problem, we need to calculate the distance between the character and 'a', and by adding it to the character, we need to shift the character. The solution approach is to find the difference between the ASCII values of both characters, and add it to the current character's ASCII value. Problem statement - We have given an alpha string of length N containing only alphabetical characters. We need to encode the string according to the below conditions. Take a distance between the current character and 'a'. ... Read More

Queries for Rotation and Kth Character of a String in Constant Time

Shubham Vora
Updated on 24-Aug-2023 16:53:07

117 Views

In this problem, programmers require to execute the queries on the string. Also, need to rotate the string and print the characters of the updated string. The best approach to solve the problem is that keep updating the index value and access string characters when we need to print the character. Problem statement – We have given the string alpha and the array containing the pair of numbers named ‘que’. The task is that perform the queries given in the array onto the string alpha. Follow the below query operation rules. (1, a) – Make total left rotations of ... Read More

Check String Formation with Circular Clockwise Shifts in Java

Shubham Vora
Updated on 24-Aug-2023 16:45:26

132 Views

In this problem, we need to convert one string to another by performing at most x circular shift operations on each character of the first string. The naïve approach to solving the problem is to rotate each character of the alpha1 string for x times, and we check if it matches the character of the alpha2 string, which is at the same index. The second approach is to solve the problem by finding the circular difference between characters at the same index. Problem statement – We have given a positive integer X. Also, we have given a string alpha1 ... Read More

Encode Given String by Inserting in Matrix Column-wise

Shubham Vora
Updated on 24-Aug-2023 16:42:49

167 Views

In this problem, we will encode the string by inserting it in the matrix in a column-wise manner and printing the string in a row-wise manner. The naïve approach to solve the problem is to create a matrix, fill the matrix top-bottom manner, and print the string row-wise. The second solution is to use the vector to store the string and print each vector value individually. Here, we will learn both approaches to solve the problem. Problem statement – We have given string str of length N. Also, we have given the positive integer rows. The task is to encode ... Read More

Difference Between String Concatenation Using str + s and str + s

Shubham Vora
Updated on 24-Aug-2023 16:40:30

226 Views

In this tutorial, we will learn the difference between the concatenation of string using the ‘+=’ or ‘+’ operator. Both operators are used to merge strings, but we learn some differences below with examples. What is Addition Assignment (+=) operator? The addition assignment (+=) operator concatenates the two strings. It takes two operands. The left operand is the original string, and the right operand is a string we need to concatenate with the original string. Generally, we use the ‘+=’ operator when we require to concatenate only two strings. Syntax Users can follow the syntax below to use the addition ... Read More

Decrypt Encoded String Using Matrix Based Technique

Shubham Vora
Updated on 24-Aug-2023 16:35:44

240 Views

In this problem, we need to decrypt the given ciphertext by traversing the matrix diagonally. We can solve the problem by traversing the matrix diagonally. Also, we require to traverse only the upper part of the matrix diagonally to get the decrypted string. Problem statement – We have given an encrypted string of length N and row counts. We need to put the string in the matrix in a row-wise manner. After that, we need to traverse the matrix diagonally, starting from the [0, 0] index to decrypt the string. Sample examples Input str = "TRSI_ _ _UIPN _ ... Read More

Count of 3-Sized Strings of All Same or Different Characters Using Total X 0s, Y 1s and Z 2s

Shubham Vora
Updated on 24-Aug-2023 16:34:30

113 Views

In this problem, we will count the number of strings we can create using the given frequencies such that the string contains same or different characters. We have four options to create a string of length 3 using the 0, 1, and 2 characters. The first string is 012, 000, 111, and 222. So, we need to count the total number of such strings to get the answer. Problem statement – We have given three integer values: X, Y, and Z. The X represents the frequency of the ‘0’, Y represents the frequency of the ‘1’, and Z represents the ... Read More

Convert Characters of String by Incrementing or Decrementing Lexicographically

Shubham Vora
Updated on 24-Aug-2023 16:31:03

120 Views

In this problem, programmers require to make all characters of str1 equal to any character of str2 by performing the increment or decrement operation. Also, we can increment or decrement rotationally. It means ‘z’ + 1 ==‘a’ and ‘a’ – 1 == ‘z’. We can solve the problem by finding the minimum cost of making the str1 string’s character equal to any character of the string str2. For each character, we can find the minimum required operations and sum them all. Problem statement – We have given two strings named str1 and str2. The size of the str1 is ... Read More

Find Maximum Consecutive 0s in Binary String Rotation

Shubham Vora
Updated on 24-Aug-2023 16:29:34

186 Views

In this problem, we need to find the maximum consecutive zeros at the start and end of string rotation. We can follow two approaches to solve the problem. The first approach is to find all rotations of the given string and count start and end zeros. The second approach is to count the maximum consecutive zeros in the string and get the answer. Problem statement – We have given the binary string named str of size equal to ‘len’. We need to count the maximum number of consecutive zeros at the start and end of any rotation of the string. ... Read More

Plot a Function Defined with def in Python Matplotlib

Rishikesh Kumar Rishi
Updated on 24-Aug-2023 16:23:56

74K+ Views

To plot a function defined with def in Python, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a user-defined function using, def, i.e., f(x).Create x data points using numpy.Plot x and f(x) using plot() method.To display the figure, use show() method.Exampleimport numpy as np from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True def f(x):    return np.sin(x) + x + x * np.sin(x) x = np.linspace(-10, 10, 100) plt.plot(x, f(x), color='red') plt.show()OutputRead More

Advertisements