
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

439 Views
Suppose we have an array called nums. We have to find the absolute sum of a subarray [nums_l, nums_l+1, ..., nums_r-1, nums_r] is |nums_l + nums_l+1 + ... + nums_r-1 + nums_r|. We have to find the maximum absolute sum of any subarray of nums (that subarray can possibly be empty).So, if the input is like nums = [2, -4, -3, 2, -6], then the output will be 11 because the subarray [2, -4, -3, 2] has maximum absolute subarray sum |2 + (-4) + (-3) + 2| = 11.To solve this, we will follow these steps −n:= size of ... Read More

240 Views
Suppose we have an array of positive calues candiesCount where candiesCount[i] denotes the number of candies of the ith type we have. We also have another another array called queries where queries[i] has three parameters [favoriteType_i, favoriteDay_i, dailyCap_i]. We have some rules:We start eating candies on day 0.We cannot eat any candy of type i unless we have eaten all candies of previous i-1 types.We must eat at least one candy per day until we have eaten all of them.Maintaining these rules, we have to make an array of Boolean values for each query results and i-th entry is true ... Read More

728 Views
Suppose, we are given a graph that contains n vertices numbered 0 to n -1. The graph is undirected and each edge has a weight. So given the graph, we have to find out the critical and the pseudo-critical edges in the graphs MST. An edge is called a critical edge if deletion of that edge causes the MST weight to increase. A pseudo-critical edge is an edge that can appear in all the graphs MSTs, but not all. We find out the index of the edges given the graph as input.So, if the input is likeand number of vertices ... Read More

380 Views
Suppose we have a tree with n nodes that are numbered from 0 to n-1. The tree is given by a parent array, where parent[i] is the parent of node i. The root of the tree is node 0. We have to find the kth ancestor of a given node, if the ancestor is not present, then return -1So, if the input is likethen the output will be 2 because the first ancestor of node 6 is 5 and the second is 2.To solve this, we will follow these steps −Define a function solve() . This will take parent, node, ... Read More

1K+ Views
Suppose we have an array called houses and have another value k. Here houses[i] represents the location of the ith house along a street, we have to allocate k mailboxes in the street, and find the minimum total distance between each house and its nearest mailbox.So, if the input is like houses = [6, 7, 9, 16, 22] k = 2, then the output will be 9 because if we place mailbox at 7 and 18, then minimum total distance from each house is |6-7|+|7-7|+|9-7|+|16- 18|+|22-18| = 1+0+2+2+4 = 9.To solve this, we will follow these steps −sort the list ... Read More

503 Views
Suppose there is an array of size m, represents m houses in a small city, each house must be painted with one of the n colors (the colors are labeled from 1 to n), And some houses are already painted, so no need to paint again. Those houses which are colored with same color are called neighborhood. We have the array houses, where houses[i] represents the color of the house, if the color value is 0, then it represents the house is not colored yet. We have another array called costs, this is a 2D array where costs[i, j] represents ... Read More

200 Views
Suppose, we are given a m x n grid box, where each cell has a board that is positioned either from the top-right to bottom-left, or from the top-left to the bottom-right. Now from the top cells, a ball is put into the box and we have to check if that ball reaches the bottom of the box. The grid is given as a matrix. If a cell is marked 1 the diagonal board spans from the top-left to the bottom-right; if it is marked -1 it spans from the top-right to the bottom-left corner. If n balls are put ... Read More

549 Views
Suppose, we are asked to implement a queue that can push and pop values at the front, middle, and back.We have to implement a pair of functions to push and pop for all three cases. We have to implement another function that shows the full queue at a given time.So, if the input is likepush_from_back(10)push_from_back(20)push_from_front(30)push_from_middle(40)push_from_front(50)show_queue()pop_from_back()show_queue()pop_from_front()show_queue()pop_from_middle()show_queue(), then the output will be [50, 30, 40, 10, 20[50, 30, 40, 10][30, 40, 10][30, 10]To solve this, we will follow these steps −array := array representation of the queueDefine a function push_from_front() . This will take valueinsert value into array at position 0Define a ... Read More

476 Views
Suppose we have two strings, s and t, we have to check whether s and t are close or not. We can say two strings are close if we can attain one from the other using the following operations −Exchange any two existing characters. (like abcde to aecdb)Change every occurrence of one existing character into another existing character, and do the same with the other characters also. (like aacabb -> bbcbaa (here all a's are converted to b's, and vice versa))We can use the operations on either string as many times as we want.So, if the input is like s ... Read More

170 Views
Suppose, we are given n number of points as (x, y). A vertical area is an area that is extended infinitely along the y-axis. We have to find out the vertical area between two points such that no other point is inside the area and is the widest.So, if the input is like pts = [[10, 9], [11, 11], [9, 6], [11, 9]], then the output will be 1.The areas in red and blue are optimal and there are no points inside them.To solve this, we will follow these steps −sort the list ptsfor i in range 1 to size ... Read More