
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

270 Views
Suppose we have a list of votes, where each element in the list has two elements [c_id, v_id], the c_id is the candidate id and v_id is the voter id. We have to check whether any voter has voted more than once or not.So, if the input is like [[5, 1], [5, 0], [5, 4], [5, 3], [5, 0]], then the output will be True as [5, 0] is present twiceTo solve this, we will follow these steps −make a new set named allfor each vote in votes, doinsert (vote[1]) into allreturn true when size of all is not same ... Read More

241 Views
Suppose we have a string called animals and another string called dinosaurs. Every letter in animals represents a different type of animal and every unique character in dinosaurs string represents a different dinosaur. We have to find the total number of dinosaurs in animals.So, if the input is like animals = "xyxzxyZ" dinosaurs = "yZ", then the output will be 3, as there are two types of dinosaurs y and Z, in the animal string there are two y type animal and one Z type animal.To solve this, we will follow these steps −res := 0dinosaurs := a new set ... Read More

167 Views
Suppose we have a list of numbers called nums, we have to find the number of elements x there are such that x + 1 exists as well.So, if the input is like [2, 3, 3, 4, 8], then the output will be 3To solve this, we will follow these steps −s := make a set by inserting elements present in numscount := 0for each i in nums, doif i+1 in s, thencount := count + 1return countLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, nums): s = set(nums) ... Read More

127 Views
Suppose we have a number n representing the length of an n x n board. We have to delete all cells that are diagonal to one of the four corners and return the number of empty cells.So, if the input is like n = 4,XOOXOXXOOXXOXOOXThen the output will be 8.To solve this, we will follow this formula −n*n - 2 * n +(n mod 2)Let us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, n): return n*n - 2 * n + (n%2) ob = Solution() print(ob.solve(4))Input4Output8

533 Views
Suppose we have a number n, we have to find the nth term of Connell sequence. The Connell sequence is as follows: 1. Take first odd integer: 1 2. Take next two even integers 2, 4 3. Then take the next three odd integers 5, 7, 9 4. After that take the next four even integers 10, 12, 14, 16 And so on.So, if the input is like 12, then the output will be 21To solve this, we will follow these steps −i := 1while quotient of (i *(i + 1) / 2) < n + 1, doi := i ... Read More

5K+ Views
Suppose we have two strings s0 and s1, they are representing a sentence, we have to find the number of unique words that are shared between these two sentences. We have to keep in mind that, the words are case-insensitive so "tom" and "ToM" are the same word.So, if the input is like s0 = "i love python coding", s1 = "coding in python is easy", then the output will be 2 as there are 2 common words, ['python', 'coding']To solve this, we will follow these steps −convert s0 and s1 into lowercases0List := a list of words in s0s1List ... Read More

2K+ Views
Suppose we have a matrix, we have to sort each of the columns in ascending order.So, if the input is like1121316641118then the output will be1646118112131To solve this, we will follow these steps −R := row count of matrix, C := column count of matrixres := matrix of same size as given matrix and fill with 0for col in range 0 to C, dovalues := take the elements as a vector of matrix[col]for row in range 0 to R, dores[row, col] := delete last element from valuesreturn resLet us see the following implementation to get better understanding −Example Live Democlass Solution: ... Read More

2K+ Views
Suppose we have a positve integer n, we have to find the length of its Collatz sequence. As we know Collatz sequence is generated sequentially where n = n/2 when n is even otherwise n = 3n + 1. And this sequence ends when n = 1.So, if the input is like n = 13, then the output will be 10 as [13, 40, 20, 10, 5, 16, 8, 4, 2, 1] these is the sequence.To solve this, we will follow these steps −if num is same as 0, thenreturn 0length := 1while num is not same as 1, donum ... Read More

225 Views
Suppose we have a matrix of unique strings representing the city blocks, and another list of strings containing blocks to visit. If we are at block matrix[0][0], then find the total Manhattan distance required to visit every block in order.So, if the input is likeQBCDEZGGiBlock = [H, B, C]Then the output will be 6 as "h" is 2 blocks bottom(south) and 1 block right(east), "b" is 2 blocks up(north), "c" is 1 block right(east).To solve this, we will follow these steps −coords := a map with key 'start' and value (0, 0)for each row in mat, dofor each col in ... Read More

1K+ Views
Suppose we have a string s and an integer n, we have to split the s into n-sized pieces.So, if the input is like s = "abcdefghijklmn", n = 4, then the output will be ['abcd', 'efgh', 'ijkl', 'mn']To solve this, we will follow these steps −i:= 0f:= a new listwhile i < size of s, doinsert s[from index i to i+n-1] at the end of fi := i + nreturn fLet us see the following implementation to get better understanding −Example Live Democlass Solution: def solve(self, s, n): i=0 f=[] while(i