- 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)
334 Views
Suppose we have two strings p and q, and also have a number r, we have to check whether p can be converted to q by shifting some characters clockwise at most r times. So, as an example, "c" can be turned into "e" using 2 clockwise shifts.So, if the input is like p = "abc", q = "ccc", r = 3, then the output will be True, as we can make "a" into "c" by using 2 clockwise shifts and then convert "b" into "c" by using 1 clockwise shift, for a total of 3 shifts.To solve this, we ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
2K+ Views
Suppose we have two strings S, and T, these two are representing an integer, we have to add them and find the result in the same string representation.So, if the input is like "256478921657", "5871257468", then the output will be "262350179125", as 256478921657 + 5871257468 = 262350179125To solve this, we will follow these steps −convert S and T from string to integerret = S + Treturn ret as stringLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, a, b): return str(int(a) + int(b)) ob = Solution() print(ob.solve("256478921657", "5871257468"))Input"256478921657", "5871257468"Output262350179125
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
1K+ Views
Suppose we have a list of numbers; we have to check whether the list is strictly increasing or strictly decreasing.So, if the input is like nums = [10, 12, 23, 34, 55], then the output will be True, as all elements are distinct and each element is larger than the previous one, so this is strictly increasing.To solve this, we will follow these steps −if size of nums
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
133 Views
Suppose we have a list of numbers called nums, we have to squeeze it from both the left and the right until there is one remaining element. We will return the states at each step.So, if the input is like nums = [10, 20, 30, 40, 50, 60], then the output will be[ [10, 20, 30, 40, 50, 60], [30, 30, 40, 110], [60, 150], [210] ]To solve this, we will follow these steps −ret := a list with only one element numswhile size of nums > 1, doif size of nums is same as 2, thennums ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
337 Views
Suppose we have a list of mailboxes. Here in each mailbox a list of strings is given, here each string is either "J" for junk, "P" for personal, "W" for Work. We will go through each mailbox in round robin order starting from the first mailbox, filtering out J, to form a single list and return the list.So, if the input is like mailboxes = [["W", "P"], ["J", "P", "J"], ["W"]], then the output will be ["W", "W", "P", "P"], as in order and without filtering, we have W -> J -> W -> P -> P -> J, now ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
324 Views
Suppose we have a list of numbers called nums, we have to find the number of elements that are present in the correct indices, when the list was to be sorted.So, if the input is like [2, 8, 4, 5, 11], then the output will be 2, as the elements 2 and 11 are in their correct positions. The sorted sequence will be [2, 4, 5, 8, 11]To solve this, we will follow these steps −s := sort the list numscount := 0for i in range 0 to size of nums, doif s[i] is same as nums[i], thencount := count ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
44 Views
Suppose we have a string s and a number k. Now each character in the string is either dot ('.') or 'x', where dot indicates an empty space and 'x' indicates a person. We have to check whether it's possible to choose a position to stand on such that the distance between us and the closest person to us is at least k. (Here the distance between each neighbouring indices is 1).So, if the input is like s = "x...x..", k = 2, then the output will be True, as we can stand at s[2] or s[6].To solve this, we ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
155 Views
Suppose we have a list of numbers called nums, we have to find the length of the shortest sublist in num, if the sublist is sorted, then the entire array nums will be sorted in ascending order.So, if the input is like nums = [1, 2, 5, 4, 9, 10], then the output will be 2, as Sorting the sublist [4, 3] would get us [0, 1, 3, 4, 8, 9]To solve this, we will follow these steps −f:= -1, l:= -1lst:= sort the list numsfor i in range 0 to size of nums, doif nums[i] is not same as ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
216 Views
Suppose we have a binary string s, we can delete any two adjacent letters if they are different. Finally, we have to find the length of the smallest string that we can get if we are able to perform this operation as many times as we want.So, if the input is like s = "1100011", then the output will be 1, as After deleting "10" we get "10011", then again delete "10", it will be "011", then delete "01", it will have left 1.To solve this, we will follow these steps −stack := a new listfor each c in s, ... Read More
![Arnab Chakraborty](https://www.tutorialspoint.com/assets/profiles/123881/profile/60_2940367-1661162113.png)
328 Views
Suppose we have a string s. We have to encode this by using run-length encoding technique. As we know, run-length encoding is a fast and simple method of encoding strings. The idea is as follows − The repeated successive elements (characters) as a single count and character.So, if the input is like s = "BBBBAAADDCBB", then the output will be "4B3A2D1C2B"To solve this, we will follow these steps −res := blank stringtmp := first character of scount := 1for i in range 1 to size of s, doif s[i] is not same as tmp, thenres := res concatenate count concatenate ... Read More