
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

283 Views
Suppose we have list of numbers called nums and another two variables k and t. Let us consider an operation where we choose an element say e in range [-k, k] and insert it to nums at the end. We have to find the minimum number of operations needed so the sum of the nums equals to target.So, if the input is like nums = [3, 1] k = 4 t = 19, then the output will be 4 because we can add like [3, 1, 4, 4, 4, 3] to get the sum 19.To solve this, we will follow ... Read More

721 Views
Suppose we have an array called nums, containing decimal digits of a number. For example, [2, 5, 6] is for 256. We have to add 1 with this number and return the list in same format as before.So, if the input is like nums = [2, 6, 9], then the output will be [2, 7, 0].To solve this, we will follow these steps −i := size of nums - 1while i >= 0, doif nums[i] + 1 = 0: if nums[i] + 1

793 Views
Suppose we have a list called reviews and a threshold value t. Each item in reviews[i] has [x, y] means product i had x number of 5-star rating and y number of reviews. We have to find the minimum number of additional 5-star reviews we need so that the percentage of 5-star reviews for those items list is at least t percent.So, if the input is like reviews = [[3, 4], [1, 2], [4, 6]] threshold = 78, then the output will be 7, as in total there were 8 5-star reviews and 12 reviews. To reach 78% 5-star reviews, ... Read More

304 Views
Suppose we have a string s whose length is n. We also have a list of queries Q, where Q[i] contains a pair (l, r). For each query we have to count number of different substrings of s in the inclusive range between l and r.So, if the input is like s = "ppqpp" Q = [(1, 1), (1, 4), (1, 1), (0, 2)], then the output will be [1, 8, 1, 5] becauseFor query (1, 1) the only substring is 'p' so output is 1For query (1, 4) the substrings are 'p', 'q', 'pq', 'qp', 'pp', 'pqp', 'qpp' and ... Read More

368 Views
Suppose we have two strings s and a set of query Q. Where Q[i] contains pair (l, r), for each substring of s from l to r, we have to find number of substrings s from x to y where they are similar. Two strings s and t are similar if they follow these rules −They are of same lengthFor each pair of indices (i, j), if s[i] is same as s[j], then it must satisfy t[i] = t[j], and similarly if s[i] is not same as s[j], then t[i] and t[j] must be different.So, if the input is like ... Read More

160 Views
Suppose, we have two strings. We want to make a lexically minimum string from those strings. To make the string we compare the first letter of the two strings and extract the lexically smaller letter from one of the strings. In the case of a tie i.e, the letters are the same; we extract the letter from the first string. We repeat this process until both the strings are empty. The minimal string constructed has to be returned.So, if the input is like input_1 = 'TUTORIALS', input_2 = 'POINT', then the output will be POINTTUTORIALSIf we compare the two strings, ... Read More

1K+ Views
Suppose we are given an array and asked to perform insertion sort on it. In insertion sort, each element in an array is shifted to its correct position in the array. We have to find out the total number of shifts required to sort an array. The total number of shifts is an integer number and if the array is already sorted, we return 0.So, if the input is like input_array = [4, 5, 3, 1, 2], then the output will be 8[4, 5, 3, 1, 2] = 0 shifts [4, 5, 3, 1, 2] = 0 shifts ... Read More

2K+ Views
plt.Show() would help whenever there is no interactive plot.fig.Show() would help to display all the figures if it is interactive.Let's take an example to observe the difference between plt.Show() and fig.Show().StepsOpen iPython shell.Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Plot a line using plot() method.Display the figure using Show() method.To display the figure, use Show() method with block=False.Exampleimport numpy as np from 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 fig ... Read More

5K+ Views
To remove the axis tick marks on a Seaborn heatmap, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create random data points with 4×4 dimension.Plot the rectangular data as a color-encoded matrix.Use tick_params() for changing the appearance of ticks and tick labels. Use left=false and bottom=false to remove the tick marks.To display the figure, use Show() method.Exampleimport numpy as np import seaborn as sns from matplotlib import pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.rand(4, 4) ax = sns.heatmap(data, vmax=1) ax.tick_params(left=False, bottom=False) ... Read More

206 Views
To make logically shading region for a curve in matplotlib, we can take the following stepsStepsSet the figure size and adjust the padding between and around the subplots.Create t, s1 and s2 data points using numpy.Create a figure and a set of subplots.Plot t and s1 data points; add a horizontal line across the axis.Create a collection of horizontal bars spanning *yrange* with a sequence of xranges.Add a '~.Collection' to the axes' collections; return the collection.To display the figure, use Show() method.Exampleimport numpy as np import matplotlib.pyplot as plt import matplotlib.collections as collections plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True ... Read More