Suppose we are provided with a string str. A border of a string is a substring that is a proper prefix and a suffix of that string. For example, 'ab' is a border of the string 'ababab'. A border is called a palindrome border if the border string is a palindrome. Now suppose there is f(str) number of palindrome borders in the given string str. We have to find out the sum of f(str_k) for all non-empty substrings str_k of str. The sum can be large, so a modulo operation can be performed by 10^9 + 7.So, if the input ... Read More
Suppose we are provided n number of strings; str1, str2, str3, ....., strn. Now, let's suppose that substri is a set that contains all the substrings of stri. The union of all the substr sets is substr_union. We now are given q number of queries, and we have to find the q-th element of the set substr_union. The set substr_union is lexicographically sorted and the indexes start from 1.So, if the input is like list of strings are = ['pqr', 'pqt'], queries are = [4, 7, 9], then the output will be ['pqt', 'qt', 't']The substrings from the first string ... Read More
Suppose we have one regular polygon with n sides represented as a binary string of size n. The vertices can be colored either in blue (0) or in red (1). They are colored in clockwise direction We have to count number of isosceles triangles whose vertices are vertices of the regular polygon, and their colors are same.So, if the input is like polygon = "111010", then the output will be 2 becausethere are two triangles ACE and AFE.To solve this, we will follow these steps −Define a function all() . This will take nif n mod 2 is same as ... Read More
Suppose, we are provided with two strings. The first one has a length greater than the second one, and we have to check if the substrings from the first string match exactly with the second string or differ in one position. We return the indexes of the first string, where the substrings that can match with the second string start.So, if the input is like string1 = 'tpoint', string2 = 'pi', then the output will be 1 2.The substring from the first string that matches with the second string or differs in one position at index 1 and 2 are ... Read More
Suppose we have two arrays called nums1 and nums2, they have same number of elements N. Now consider a set S with N elements from 1 through N. We have to find the value of (nums1[i1] + nums1[i2] + ... nums1[ik])^2 + (nums2[i1] + nums2[i2] + ... nums2[ik])^2 where {i1, i2, ... ik} is non empty subset of the set S.So, if the input is like nums1 = [-1, 6] nums2 = [5, 4], then the output will be 106 because(-1)^2 + (5)^2 = 26(6)^2 + (4)^2 = 50(-1 + 6)^2 + (5 + 4)^2 = 106To solve this, we ... Read More
Suppose, we are given a string 'input_str'. If we determine all the suffixes from input_str; for example if the string is 'abcd', the suffixes are 'abc', 'bcd', 'cd', 'd'. Now, we check the similarity between input_str and all the suffixes by the length of the longest common prefix in input_str and a suffix. The sum of the similarities between input_str and all the suffixes has to be returned.So, if the input is like input_str = 'tpotp', then the output will be 7All the suffixes from the string 'tpotp' are 'tpotp', 'potp', 'otp', 'tp', and 'p'.If we check the similarity of ... Read More
Suppose, we are given a string 'input_str'. Now, we are asked to determine every possible substring from the given string then concatenate all the substrings one after another in a lexical order into another string. We are also provided an integer value k. Our task is to return the letter at index k from the concatenated string.So, if the input is like input_str = 'pqrs', k = 6, then the output will be pThe substrings from the given string in lexical order are p, pq, pqr, pqrs, q, qr, qrs, r, rs, s.If we concatenate the strings, it becomes ppqpqrpqrsqqrqrsrrss. ... Read More
Suppose, we are given a number n and are asked to write all the possible permutations with the positive integers up to n. The permutations are then sorted lexicographically and numbered from 1 to n. Among all the permutations, one permutation is taken and is termed as the special permutation. Now, among the special permutation; the values can be forgotten. The forgotten values are then replaced with 0s. We have to find the permutations that can be equal to the original permutations and then we add their perspective number to obtain a sum. The sum value is returned as the ... Read More
plt.figure() − Creates a new figure or activates an existing figure.plt.subplots() − Creates a figure and a set of subplots.Let's take an example to understand the difference between plt.subplots() and plt.figure().StepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure. Use plt.figure() method.Create a figure and a set of subplots. Use plt.subplots() method.To display the figure, use Show() method.Examplefrom matplotlib import pyplot as plt # Set the figure size plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True # Create a new figure using plt.figure fig1 = plt.figure("Figure 1 ... Read More
To create a custom mouse cursor in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Bind the function *mouse_event* to the event *button_press_event*.Create x and y data points using numpy.Plot the x and y data points 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.00, 3.50] plt.rcParams["figure.autolayout"] = True def mouse_event(event): print('x: {} and y: {}'.format(event.xdata, event.ydata)) fig = plt.figure() cid = fig.canvas.mpl_connect('button_press_event', mouse_event) ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP