
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

322 Views
Suppose we are given a binary string input_str that contains 0s and 1s. Our task is to group the 0s and 1 by swapping the 1s in the given string. We have to perform a minimum number of swap operations, and we have to return that value. One thing to be kept in mind, we can swap the adjacent values only.So, if the input is like input_str = 10110101, then the output will be 4The swap will be like following −10110101->01110101->01111001->01111010->01111100The total number of swaps: 4.To solve this, we will follow these steps −one := a new list containing the ... Read More

421 Views
Suppose we have two lists nums1 and nums2. Each of these two list are representing a vector in run-length encoded form. So as an example, a vector [1, 1, 1, 2, 2, 2, 2] is represented as [3, 1, 4, 2]. (because there are 3 ones and 4 twos). So we have to find the dot product of these two vectors. (The dot product is the sum of element wise multiplication of items present in two vectors).So, if the input is like nums1 = [2, 7, 5, 3] nums2 = [3, 5, 4, 2], then the output will be 109 ... Read More

348 Views
Suppose we have an edge list of a directed graph, there are n nodes and node names are 0 to n- 1. We also have two integer values a and b. We have to check whether there is any node c such that we can go from c to a and also c to b.So, if the input is likeAnd a = 2, b = 3, then the output will be True, because here c = 0, so we have route from 0 to 2 and also 0 to 3.To solve this, we will follow these steps −Define a function ... Read More

206 Views
Suppose we have a 2D matrix where each cell matrix[r, c] represents the number of coins present in that cell. When we pick up coins from matrix[r, c], all the coins on row (r - 1) and (r + 1) will disappear, as well as the coins at the two cells matrix[r, c + 1] and matrix[r, c - 1]. We have to find the maximum number of coins we can collect.So, if the input is like28761010425923then the output will be 26 because we can pick cells with the coins 8, 6, and 9 and 3, so total is 26.To ... Read More

162 Views
Suppose we have two lists, they are cores and tasks. The cores[i] indicates number of cores available in the ith server. And tasks[i] indicates the number of cores needed to execute that task. Each task must be run in only one server. And a server may have multiple tasks to run. We have to check whether it's possible to run all the tasks with the given cores or not.So, if the input is like cores = [10, 7] tasks = [7, 3, 2, 2, 1], then the output will be True, because we can put tasks[0] and tasks[1] into first ... Read More

285 Views
Suppose we have a circular list called nums. So the first and the last elements are neighbors. So starting from any index say i, we can move nums[i] number of steps forward if nums[i] is a positive value, otherwise backwards if it's a negative value. We have to check whether there is a cycle whose length is greater than one such that the path only goes forwards or only goes backwards.So, if the input is like nums = [-1, 2, -1, 1, 2], then the output will be True, because there is a forward path [1 -> 3 -> 4 ... Read More

545 Views
Suppose we have a string s which consists of only three characters "X", "(", and ")". The string has balanced brackets and in between some "X"s are there along with possibly nested brackets may also there recursively. We have to find the number of "X"s at each depth of brackets in s, starting from the shallowest depth to the deepest depth.So, if the input is like s = "(XXX(X(XX))XX)", then the output will be [5, 1, 2]To solve this, we will follow these steps −depth := -1out := a new listfor each c in s, doif c is same as ... Read More

668 Views
Suppose we have a lowercase string s and another list of integers called shifts whose length is same as the length of s. Here each element in shifts[i] indicates it to shift the first i + 1 letters of s by shifts[i] positions. If shifting crosses 'z' it will be wrap up to 'a'. We have to find the resulting string after applying shifts to s.So, if the input is like s = "tomato" shifts = [2, 5, 2, 3, 7, 4], then the output will be "qjcoes" so, after shifting first character 2 places, it will be 't' to ... Read More

266 Views
Suppose we have a list of numbers called bricks and two other values width and height. Each element in bricks[i] represents a brick whose length is bricks[i] units and width is 1 unit. We have to find the number of ways to lay the bricks such that we get full layout of bricks with the given width and height. We can reuse the bricks but can only be laid horizontally.So, if the input is like bricks = [2, 1] width = 3 height = 2, then the output will be 9 because −To solve this, we will follow these steps ... Read More

215 Views
Suppose we have two list of numbers nums1 and nums2. And also have two numbers lower and upper. We have to find the number of pairs (i, j) such that lower ≤ nums1[i]^2 + nums2[j]^2 ≤ upper.So, if the input is like nums1 = [5, 3, 2] nums2 = [8, 12, 6] lower = 10 upper = 50, then the output will be 2 because the pairs are like (1, 2) and (2, 2)10