- 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)
316 Views
Suppose we have an array A of n values (elements may not be distinct). We have to find the sum of maximum difference possible from all subsets of given array. Now consider max(s) denotes the maximum value in any subset, and min(s) denotes the minimum value in the set. We have to find the sum of max(s)-min(s) for all possible subsets.So, if the input is like A = [1, 3, 4], then the output will be 9.To solve this, we will follow these steps −n := size of Asort the list Asum_min := 0, sum_max := 0for i in range ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
210 Views
Suppose we have a given integer N; we have to find the sum of all Truncatable primes less than N. As we know the truncatable prime is a number which is left-truncatable prime (if the leading "left" digit is successively removed, then all resulting numbers are treated as prime) as well as right-truncatable prime (if the last "right" digit is successively removed, then all the resulting numbers are treated as prime). An example of truncatable prime is 9137 as this is lefttruncatable prime because 9137, 137, 37 and 7 are primes. Hence 9137 is a truncatable prime.So, if the input ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
357 Views
Suppose we have two strings s1 and s2, we have to find the smallest substring in s1 such that all characters of s2 will be used efficiently.So, if the input is like s1 = "I am a student", s2 = "mdn", then the output will be "m a studen"To solve this, we will follow these steps −N := 26str_len := size of main_str, patt_len := size of patternif str_len < patt_len, thenreturn Nonehash_pat := an array of size N and fill with 0hash_str := an array of size N and fill with 0for i in range 0 to patt_len, dohash_pat[ASCII ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
491 Views
Suppose we have a sorted array of positive numbers, this array is sorted in ascending order, er have to find the smallest positive value that cannot be represented as sum of elements of any subset of given set. We have to solve this problem in O(n) time.So, if the input is like A = [1, 4, 8, 12, 13, 17], then the output will be 2.To solve this, we will follow these steps −n := size of Aanswer := 1for i in range 0 to n, doif A[i]
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
260 Views
Suppose we have a Markov chain graph g; we have the find the probability to reach the state F at time T if we start from state S when time t = 0. As we know a Markov chain is a random process consisting of various states and the probabilities to move one state to another. This can be represented as a directed graph; the nodes are states and the edges have the probability of going from one node to another. From one state to another, it takes unit time to move. The sum of the probabilities of the outgoing ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
179 Views
Suppose we have two arrays A and B. The size of A is the number of rows and A[i] is the number of boxes in the ith row. And B is the array of balls where B[i] denotes a number on the ball. Given that ball i (value B[i]) will be placed in a box whose position from starting is B[i]. We have to find the row and column of the boxes corresponding to each B[i].So, if the input is like A = [3, 4, 5, 6], B = [1, 3, 5, 2], then the output will be [(1, 1), ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
70 Views
Suppose we have a string S with lowercase letters, now two players are playing the game. The rules are as follows −The player wins the game, if, at any move, a player can shuffle the characters of the string to get a palindrome string.The player cannot win when he/she has to remove any character from the string.We have to keep in mind that both players play the game optimally and player1 starts the game. We have to find the winner of the game.So, if the input is like "pqpppq", then the output will be Player1 as player-1 in the first ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
166 Views
Suppose we have two arrays A and B of size N and M respectively and we also have one N X M binary matrix where 1 denotes that there was a positive integer in the original matrix and 0 means that position is holding 0 into the original matrix also. We have to generate the original matrix so that A[i] denotes the largest element in the ith row and B[j] denotes the largest element in the jth column.So, if the input is like A = [4, 2, 3], B = [3, 1, 0, 0, 4, 0, 5] matrix, then the ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
357 Views
Suppose we have n different tasks; these tasks are labeled from 0 to n-1. Some tasks may have prerequisites tasks, so as an example if we want to choose task 2 then we have to first finish the task 1, which is represented as a pair − [2, 1] If we have total number of tasks and a list of prerequisite pairs, we have to find the ordering of tasks to finish all tasks. If there are more than one correct order, we can just return one of them. And if it is impossible to finish all given tasks, return ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
250 Views
Suppose we have an array A containing the permutation of first N natural numbers and another number M is also given, where M ≤ N, we have to find the number of sub-arrays such that the median of the sequence is M. As we know the median of a sequence is defined as the value of the element which is in the middle of the sequence after sorting it according to ascending order. For even length sequence, the left of two middle elements is used.So, if the input is like A = [3, 5, 6, 4, 2] and M = ... Read More