- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 10783 Articles for Python
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
180 Views
Suppose we have two strings P and Q of same lengths with only lower case letters, we have to count the minimum number of pre-processing moves on string P are needed to make it equal to string Q after applying below operations −Select any index i and swap characters pi and qi.Select any index i and swap characters pi and pn – i – 1.Select any index i and swap characters qi and qn – i – 1.Note − The value of i in range (0 ≤ i < n)In one move we can change a character in P with any ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
277 Views
Suppose we have one N X N matrix M, and this is filled with 1, 0, 2, 3, We have to find the minimum numbers of moves required to move from source cell to destination cell. While visiting through blank cells only, we can visit up, down, right and left.Cell with value 1 indicates Source.Cell with value 2 indicates Destination.Cell with value 3 indicates Blank cell.Cell with value 0 indicates Blank Wall.There will be only one source and only one destination cells. There may be more than one path to reach destination from source cell. Now, each move in matrix ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
295 Views
Suppose we have a given unsorted array A[0..n-1] of size n, we have to find the minimum length subarray A[s..e] so that by sorting this subarray the whole array will be sorted. So, if the array is like [2, 6, 4, 8, 10, 9, 15], then the output will be 5. The subarray will be [6, 4, 8, 10, 9].To solve this, we will follow these steps −res := sort the nums as an arrayans := 0set r as a linked listfor i in range 0 to length of resif nums[i] is not same as res[i], then insert i into ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
93 Views
Suppose we have two numbers p and q, we have to find the minimum difference between any terms in the shifted infinite tables of p and q, these shifts are r and s, where r, s >= 0.So, if the input is like p = 7 and q = 17, r = 6 and s = 3, then the output will be 0 as, table of 7 = [7, 14, 21, 28, 35, 42, 49, ...] and table of 17 = [17, 34, 51, 68, 85, 102, 119, ...], then shifted table of 7 will be [13, 20, 27, 34, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
790 Views
Suppose there is a candy store where N different types of candies are available and the prices of all N different types of candies are given. The store also provides an attractive offer. According to this offer, we can buy a single candy from the store and get maximum of K different types of other candies for free. We have to find the minimum amount of money we have to spend to buy all the N different types of candies. We also have to find maximum amount of money we have to spend to buy all the N different types ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
474 Views
Suppose we have an array of size n, if the elements in the array, are in range from 0 to k-1. Where k is denoted as a positive integer and k max_val, thenmax_val := A[i]result := ireturn resultExample Let us see the following implementation to get better understanding − Live Demodef get_max_repeating(A, k): n = len(A) for i in range(n): A[A[i]%k] += k max_val = A[0] result = 0 for i in range(1, n): if A[i] > max_val: max_val = A[i] result ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
174 Views
Suppose we have a given number N that in range (1= j and table[i - j] != -1): table[i] = max(table[i], table[i - j] + 1) return table def max_summ(table, n): if (n < max_val): return table[n] else: t = int((n - max_val) / 4)+ 1 return t + table[n - 4 * t] n = 16 table = pre_calc() print(max_summ(table, n))Input16Output4
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
428 Views
Suppose there are n bikes and each can cover 100 km when they are fully fueled. We have to find the maximum amount of distance we can go using these n bikes. Here we can assume that all bikes are similar and a bike consumes 1 litre of fuel to cover 1 km distance. So, if n bikes start from same point and run parallel, we can go only 100 km, in this case our target is to cover maximum distance, with minimum fuel. And minimum wastage of fuel means minimum number of bikes used. If the bikes run serially, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
526 Views
Suppose we have a string we have to return the longest possible substring that has exactly k number of unique characters, if there are more than one substring of longest possible length, return any of them.So, if the input is like s = "ppqprqtqtqt", k = 3, then the output will be rqtqtqt as that has length 7.To solve this, we will follow these steps −N := 26Define a function is_ok() . This will take count, kval := 0for i in range 0 to N, doif count[i] > 0, thenval := val + 1return true when (k >= val)From the ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
379 Views
Suppose we have an array A of n different numbers and another positive integer K, we have to find the longest sub-sequence in the array having Least Common Multiple (LCM) at most K. After than return the LCM and the length of the sub-sequence, following the indexes (starting from 0) of the elements of the obtained sub-sequence. Otherwise, return -1.So, if the input is like A = [3, 4, 5, 6], K = 20, then the output will be LCM = 12, Length = 3, Indexes = [0, 1, 3]To solve this, we will follow these steps −n := size ... Read More