- 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
161 Views
Suppose we have a list of numbers called nums, we have to find the maximum length of a contiguous strictly increasing sublist when we can remove one or zero elements from the list.So, if the input is like nums = [30, 11, 12, 13, 14, 15, 18, 17, 32], then the output will be 7, as when we remove 18 in the list we can get [11, 12, 13, 14, 15, 17, 32] which is the longest, contiguous, strictly increasing sublist, and its length is 7.To solve this, we will follow these steps−n := size of numspre := a list ... Read More
467 Views
Suppose we have two strings s and t of length n. We can take one character from s and another from t and swap them. We can make unlimited number of swaps; we have to check whether it's possible to make the two strings equal or not.So, if the input is like s = "xy", t = "yx", then the output will be TrueTo solve this, we will follow these steps −st:= sort the string after concatenating s and tfor i in range 0 to size of st - 1, increase by 2, doif st[i] is not same as st[i+1], ... Read More
462 Views
Suppose we have a string s, we have to find the length of the longest substring with same characters.So, if the input is like "abbbaccabbbba", then the output will be 4, as there are four consecutive b's.To solve this, we will follow these steps −if size of s is 0, thenreturn 0s := s concatenate blank spacect:= 1, tem:= 1for i in range 0 to size of s -2, doif s[i] is same as s[i+1], thentem := tem + 1otherwise, ct:= maximum of tem and cttem:= 1return ctLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More
2K+ Views
Suppose we have a list of lowercase strings, we have to find the longest common prefix.So, if the input is like ["antivirus", "anticlockwise", "antigravity"], then the output will be "anti"To solve this, we will follow these steps −sort the list words alphabeticallyprefix := a new listflag := 0for i in range 0 to size of words[0], dofor each j in words, doif j[i] is not same as last element of prefix, thendelete last element from prefixflag := 1come out from the loopif flag is same as 1, thencome out from the loopreturn string after concatenating all elements present in prefix ... Read More
167 Views
Suppose we have a list of numbers called nums, we have to replace every nums[i] with the smallest element left of i. We have to replace nums[0] with 0.So, if the input is like [15, 7, 9, 16, 12, 25], then the output will be [0, 15, 7, 7, 7, 7]To solve this, we will follow these steps −if nums is empty, thenreturn a new listj:= nums[0]nums[0]:= 0for i in range 1 to size of nums - 1, dok:= nums[i]nums[i]:= jj:= minimum of j, kreturn numsLet us see the following implementation to get better understanding −Example Live Democlass Solution: def ... Read More
420 Views
Suppose we have given a list of numbers called nums, we want to make the values equal. Now let an operation where we pick one element from the list and increment every other value. We have to find the minimum number of operations required to make element values equal.So, if the input is like [2, 4, 5], then the output will be 5.To solve this, we will follow these steps −min_val := minimum of numss := 0for each num in nums, dos := s + (num - min_val)return sLet us see the following implementation to get better understanding −Example Live Democlass ... Read More
274 Views
Suppose we have a list of numbers called nums, we also have another string op representing operator like "+", "-", "/", or "*", and another value val is also given, we have to perform the operation on every number in nums with val and return the result.So, if the input is like [5, 3, 8], then the output will be [15, 9, 24]To solve this, we will follow these steps −res:= a new listfor each i in nums, doif op is same as '+', theninsert i+val at the end of resotherwise when op is same as '-', theninsert i-val at ... Read More
1K+ Views
Suppose we have a singly linked list. the linked list is representing a binary number with most significant digits first, we have to return it as decimal number.So, if the input is like [1, 0, 1, 1, 0], then the output will be 22To solve this, we will follow these steps −l := a new listwhile node is not null, doinsert value of node at the end of lnode:= next of nodek := 0, v:= 0for i in range size of l - 1 to 0, decrease by 1, doif l[i] is same as 1, thenv := v + 2^kk ... Read More
331 Views
Suppose we have a singly linked list, and one target, we have to return the same linked after deleting all nodes whose value is same as target.So, if the input is like [5, 8, 2, 6, 5, 2, 9, 6, 2, 4], then the output will be [5, 8, 6, 5, 9, 6, 4, ]To solve this, we will follow these steps −head := nodewhile node and node.next are not null, dowhile value of next of node is same as target, donext of node := next of next of nodenode := next of nodeif value of head is same as ... Read More
3K+ Views
Suppose we have a string s, we have to find the lexicographically smallest string that can be made if we can make at most one swap between two characters in the given string s.So, if the input is like "zyzx", then the output will be "xyzz"To solve this, we will follow these steps −temp := an array of size s and fill with 0m:= size of s - 1for i in range size of s -1 to -1, decrease by 1, doif s[i] < s[m], thenm := itemp[i] := mfor i in range 0 to size of s, doa := ... Read More