- 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 10784 Articles for Python
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
149 Views
Suppose we have a two-dimensional matrix M. Now in each cell contains a value that represents its color, and adjacent cells (top, bottom, left, right) with the same color are to be grouped together. Now, consider an operation where we set all cells in one group to some color. Then finally find the minimum number of operations required so that every cell has the same color. And when the color is transformed, it cannot be set again.So, if the input is like222211112321Then the output will be 2, as We can fill the group with 2 as color into 1 and ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
1K+ Views
Suppose we have a 2D matrix where each cell stores some coins. If we start from [0, 0], and can only move right or down, we have to find the maximum number of coins we can collect by the bottom right corner.So, if the input is like14220005then the output will be 14, as we take the path: [1, 4, 2, 2, 5]To solve this, we will follow these steps−for r in range 1 to row count of A, doA[r, 0] := A[r, 0] + A[r-1, 0]for c in range 1 to column count of A, doA[0, c] := A[0, c] ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
104 Views
Suppose we have a list of numbers called nums. We have to find a new list of the same length where the value at index i is assigned to the next element greater than nums[i] to its right, circling back to the front of the list when required. If there is no number that is greater, then it should be set to -1.So, if the input is like [4, 5, 1, 3], then the output will be [5, -1, 3, 4]To solve this, we will follow these steps−n := size of astack := a stack, insert 0 initially, res := ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
237 Views
Suppose we have a singly linked list node, we have to find the value of the middle node. And when there are two middle nodes, then we will return the second one. We have to try to solve this in single pass.So, if the input is like [5, 9, 6, 4, 8, 2, 1, 4, 5, 2], then the output will be 2.To solve this, we will follow these steps−p:= noded:= 0, l:= 0while node is not null, doif d is not same as 2, thennode:= next of nodel := l + 1, d := d + 1otherwise, p:= next ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
358 Views
Suppose we have a list of cards, and we want to order the cards in a way so that they are revealed in ascending order. As we know, the cards are revealed in this manner: 1. The top most card is removed and revealed and then next card is gone to the back. 2. Step 1 is repeated until there's no more cards. We have to find an ordering of the cards such that they are revealed in ascending order.So, if the input is like cards = [1, 2, 3, 4, 5, 6, 7, 8], then the output will be ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
203 Views
Suppose we have two non-empty strings s and t that are of the same length. We have to partition them into substrings such that each pair of s and t substring is the same size and they are the anagrams of each other. Now find the cut indexes such that it results in the maximum number of cuts of s and t. If no result is found, then return empty list.So, if the input is like s = "bowcattiger" t = "owbactietgr", then the output will be [0, 3, 5, 6, 10], as we can partition the string into 5 ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
325 Views
Suppose we have a list of numbers called nums, now consider every contiguous subarray. Sum each of these subarray and return the sum of all these values. Finally, mod the result by 10 ** 9 + 7.So, if the input is like nums = [3, 4, 6], then the output will be 43, as We have the following subarrays − [3] [4] [6] [3, 4] [4, 6] [3, 4, 6] The sum of all of these is 43.To solve this, we will follow these steps −N:= size of numsans:= 0for i in range 0 to size of nums, don:= nums[i]ans ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
305 Views
Suppose we have a list of numbers called nums and another number k. If we start at index k and at any index i, we can go either left or right by exactly nums[i] number of steps. We have to check whether we can reach the end of the list or not.So, if the input is like nums = [0, 0, 2, 1, 3, 3, 1, 1] k = 2, then the output will be True, as if we start at index 2, then jump to index 4 and then jump to the last index 7.To solve this, we will ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
154 Views
Suppose we have a staircase with n steps and we also have another number k, initially we are at stair 0, and we can climb up either 1, 2 or 3 steps at a time. but we can only climb 3 stairs at most k times. Now we have to find the number of ways we can climb the staircase.So, if the input is like n = 5, k = 2, then the output will be 13, as there are different ways we can climb the stairs −[1, 1, 1, 1, 1][2, 1, 1, 1][1, 2, 1, 1][1, 1, 2, ... Read More