
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

102 Views
Suppose, there are n number of hostel rooms numbered from 0 to n-1. The students in the hostel rooms want to transfer to another room, and they place several requests to do that. No hostel seat remains vacant, a transfer request is only taken care of if another student takes the place of the student willing to transfer. So, given the requests, we have to find out how many requests can be satisfied.So, if the input is like n = 3, requests = [[0, 2], [1, 0], [2, 1]], then the output will be 3.The student in room 0 transfers ... Read More

422 Views
Suppose, we are given a grid where the cells contain various symbols such as 'X', 'O', '*' and '#' and the symbols have various meanings.'#' is the goal cell that we want to reach.'O' is a free cell via which we can travel to the goal cell.'*' is our position in the cell.'X' is a blocked cell, via which we cannot travel.We have to find out the number of moves required to reach the goal cell from our current position in the grid. If the goal is not reachable, we return -1. The grid is given as input to the ... Read More

321 Views
Suppose we have an m x n binary matrix, we can rearrange the columns of the matrix in any order. We have to find the area of the largest submatrix within matrix where every element of the submatrix is 1 after performing some reordering task.So, if the input is like101111001then the output will be 4 because, after column swapping we are getting matrix like110111010here maximum submatrix is of square sized with four 1's.To solve this, we will follow these steps βrow := number of rows of matrix, col := number of columns of matrixfor j in range 0 to col ... Read More

497 Views
Suppose we have an array nums with unique positive values, we have to find the number of tuples (a, b, c, d) such that a*b = c*d where a, b, c, and d are elements of nums, and all elements a, b, c and d are distinct.So, if the input is like nums = [2, 3, 4, 6], then the output will be 8 because we can get tuples like (2, 6, 3, 4), (2, 6, 4, 3), (6, 2, 3, 4), (6, 2, 4, 3), (3, 4, 2, 6), (4, 3, 2, 6), (3, 4, 6, 2), (4, 3, ... Read More

198 Views
Suppose we have three numbers i, j and k and another number n. We shall have to find the list of all triplets (i, j, k) for which i+j+k not same as n. We shall have to solve this problem using list comprehension strategy.So, if the input is like i = 1, j = 1, z = 2 and n = 3, then the output will be [[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 2]]To solve this, we will follow these ... Read More

302 Views
Suppose we have two integer arrays, src and tgt, both are of same length. We also have an array allowedSwaps where allowedSwaps[i] contains a pair (ai, bi) indicates that we can swap the elements at index ai with element index bi of the array src. (We can swap elements at a specific pair of indices as many times as we want in any order). As we know the Hamming distance of two arrays of the same length, src and tgt, is the number of positions where the elements are different. We have to find the minimum Hamming distance of src ... Read More

1K+ Views
Suppose we have a number n. We shall have to check whether n is weird or not. Here a number is weird when β 1. The number is odd 2. The number is not in range 2 to 5 3. The number is even and in range 6 to 20So, if the input is like n = 18, then the output will be Weird because it is even and in range 6 to 20.To solve this, we will follow these steps βif n is odd, thenreturn "Weird"otherwise when (n > 1 and n < 6) or n > 20, thenreturn ... Read More

313 Views
Suppose we have a list of numbers nums. We also have a list of queries where queries[i] contains three elements [k, p, r], for each query we shall have to find kpr_sum. The formula for kpr_sum is like below.$$\mathrm{{πππ}\_{π π’π} =\sum_{\substack{π=π}}^{π β1}\sum_{\substack{π=π+1}}^{π }(πΎ β(π΄[π]βπ΄[π]))}$$If the sum is too large, then return sum modulo 10^9+7.So, if the input is like nums = [1, 2, 3] queries = [[1, 1, 3], [2, 1, 3]], then the output will be [5, 4] because for the first element it is (1 XOR (1 XOR 2)) + (1 XOR (1 XOR 3)) + (1 XOR (2 XOR 3)) ... Read More

1K+ Views
Suppose we have a list L and another value k. We have to swap kth node from start and kth node from end and return the final list at end.So, if the input is like L = [1, 5, 6, 7, 1, 6, 3, 9, 12] k = 3, then the output will be [1, 5, 3, 7, 1, 6, 6, 9, 12], the 3rd node from start is 6 and from end is 3, so they are swapped.To solve this, we will follow these steps βtemp := Lfor i in range 0 to k-2, dotemp := next of tempfirstNode ... Read More

124 Views
Suppose there is a sensor module that can monitor its nearby environment up to a radius of r. There are some things in the lattice point of the module's monitoring circle that needs to be monitored. So, k number of low-powered modules are placed so that they can monitor only those specific points. Given the square of the radius and k number of low-powered modules, we shall have to find out if the points can be monitored correctly. We return true if monitoring is possible, otherwise, we return false.So, if the input is like square of radius (j) = 4, ... Read More