
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 10476 Articles for Python

262 Views
Suppose we have a string s with only "a" and "b". "a"s can stay "a" or turn into "b", but "b"s can not be changed. We have to find the number of unique strings that we can make.So, if the input is like s = "baab", then the output will be 4, as We can make these strings − ["baab", "babb", "bbab", "bbbb"]To solve this, we will follow these steps −counts := frequency of 'a' in sreturn 2^countsLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, s): counts = s.count('a') ... Read More

884 Views
Suppose we have a number n, we have to check whether its prime factors only include 2, 3 or 5 or not.So, if the input is like n = 18, then the output will be True, as 18's prime factors are 2 and 3.To solve this, we will follow these steps −if n < 0, thenreturn Falsefactor := a list with elements [2, 3, 5]for each i in factor, dowhile n mod i is same as 0, don := n / ireturn true when n is same as 1, otherwise falseLet us see the following implementation to get better understanding ... Read More

667 Views
Suppose we have a number n, we have to find a string of stairs with n steps. Here each line in the string is separated by a newline separator.So, if the input is like n = 5, then the output will be * ** *** **** *****To solve this, we will follow these steps −s := blank stringfor i in range 0 to n-1, dos := s concatenate (n-i-1) number of blank space concatenate ... Read More

723 Views
Suppose we have a matrix M, we have to check whether it is a Toeplitz matrix or not. As we know a matrix is said to be Toeplitz when every diagonal descending from left to right has the same value.So, if the input is like726372537then the output will be True.To solve this, we will follow these steps −for each row i except the last one, dofor each column except the last one, doif matrix[i, j] is not same as matrix[i+1, j+1], thenreturn Falsereturn TrueLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, matrix): ... Read More

600 Views
Suppose we have three numbers, x, y, and z, we have to find their product, but if any two numbers are equal, they do not count.So, if the input is like x = 5, y = 4, z = 2, then the output will be 40, as all three numbers are distinct so their product is 5 * 4 * 2 = 40To solve this, we will follow these steps −temp_set := a new setremove := a new setfor each i in [x, y, z], doif i is in temp_set, theninsert i into the set called removeinsert i in to ... Read More

356 Views
Suppose we have a list of tasks and another list of people. The tasks[i] determines the amount of strength required to perform the ith task. And the people[i] determines the amount of strength the ith person has. Finally, we have to find the number of tasks that can be finished if one person can perform at most one task.So, if the input is like tasks = [4, 3, 9, 15], people = [10, 5, 3, 2], then the output will be 3, as the first person can perform task 9, second person can perform task 4, third person can perform ... Read More

401 Views
Suppose we have a number start and another number end (start < end), we have to find the minimum number of operations required to convert start to end using these operations −Increment by 1Multiply by 2So, if the input is like start = 5, end = 11, then the output will be 2, as we can multiply 2 to get 10, then add 1 to get 11.To solve this, we will follow these steps −ct:= 0while end/2 >= start, doif end mod 2 is same as 1, thenend := end - 1end := end/2ct := ct + 2otherwise, end:= end/2ct ... Read More

830 Views
Suppose we have a list of numbers called nums and we have another number k, we have to check whether any two numbers present in the list add up to k or now. Same elements must not be used twice. And numbers can be negative or 0.So, if the input is like nums = [45, 18, 9, 13, 12], k = 31, then the output will be True, as 18 + 13 = 31To solve this, we will follow these steps −temp_set:= a new setfor each num in nums, doif num is in temp_set, thenreturn Trueadd (k-num) into temp_setreturn FalseLet ... Read More

1K+ Views
Suppose we have a number num, we have to find the sum of its digits. We have to solve it without using strings.So, if the input is like num = 512, then the output will be 8, as 8 = 5 + 1 + 2.tput will be 8, as 8 = 5 + 1 + 2. To solve this, we will follow these steps −sum:= 0while num is not same as 0, dosum := sum + (num mod 10)num:= quotient of num/10return sumLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, num): ... Read More