
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

233 Views
Suppose we have a sorted and disjoint intervals list and another list cut, that represents an interval. We have to delete all parts of intervals that are intersecting with cut interval, and return the new list.So, if the input is like intervals = [[2, 11], [13, 31], [41, 61]] cut = [8, 46], then the output will be [[2, 8], [46, 61]]To solve this, we will follow these steps −cut_start, cut_end := cutans := a new listfor each start, end in intervals, doif maximum of cut_start and start < minimum of end and cut_end, thenif start < cut_start, theninsert interval ... Read More

531 Views
Suppose we have a list of numbers called nums and we are placed currently at nums[0]. On each step, we can either jump from the current index i to i + 1 or i - 1 or j where nums[i] == nums[j]. We have to find the minimum number of steps required to reach the final index.So, if the input is like nums = [4, 8, 8, 5, 4, 6, 5], then the output will be 3, as we can jump from index 0 to index 4 as their values are both 4. And then we jump back to index ... Read More

786 Views
Suppose we have a a friends list, where friends[i] is a list of people i is friends with. The connection of friendships are two-way. And each person is friend with themselves and two people are in a friend group as long as there is some path of mutual friends connecting them. We have to find the total number of friend groups.So, if the input is like friends = [[0, 1, 5], [1, 0], [2], [3, 4], [4, 3], [5, 0]], then the output will be 3, as The three friend groups are as below −To solve this, we will follow ... Read More

277 Views
Suppose we have a 2D binary matrix. For any row or column in the given matrix we can flip all the bits. If we can perform any number of these operations, and that we treat each row as a binary number, we have to find the largest sum that can be made of these numbers.So, if the input is like010001then the output will be 11, as if we flip both rows we get 101 and 110, then the sum is 5 + 6 = 11To solve this, we will follow these steps −for each row r in matrix, doif r[0] ... Read More

557 Views
Suppose we want to design an algorithm to serialize and deserialize a binary search tree. Serialization is the process of converting something (data structure or object) into a sequence of bits so that it can be stored in a file or memory buffer, or transmitted across a network connection link. This can be reconstructed later that process is deserialization.So, if the input is like [5, 2, 9, 1, 3, 7], then the output will be Serialized output 5.2.9.1.3.7.N.N.N.N.N.N.N Deserialized output: 1, 2, 3, 5, 7, 9, (inorder traversal)To solve this, we will follow these steps −Define a function serialize() . ... Read More

269 Views
Suppose we have a 2-dimensional array called grid, where each value of grid[i][j] represents the height of a building located there. We can increase the height of any number of buildings, by any amount. Height 0 is considered to be a building as well. At the end, the "skyline" when viewed from all four directions of the grid, must be the same as the skyline of the original grid. Because a city's skyline is the outer contour of the rectangles formed by all the buildings when viewed from a distance. So we have to find the maximum total sum that ... Read More

386 Views
Suppose we have some logs, that each log contains a unique id and timestamp. The Timestamp is a string that has the format: Year:Month:Day:Hour:Minute: Second, for example, 2019:01:01:23:59:59. All domains are zero-padded decimal numbers.We have to design a log storage system to implement the following functions −void Put(int id, string timestamp): This will take the log's unique id and timestamp, and it stores the log in the storage system.int[] Retrieve(String start, String end, String granularity): This will return the id of logs whose timestamps are within the range from start to end parameters. The granularity parameter indicates the time level ... Read More

8K+ Views
In this article, we are going to learn how to insert an item in a sorted list maintaining the order. Python has a built-in module called bisect that helps us to insert any element in an appropriate position in the list.Follow the below steps to write the code.Import the module bisect.Initialize list and element that need to insertThe module bisect has a method called insort that inserts an element into a list in an appropriate position. Use the method and insert the element.Print the list.Example Live Demo# importing the module import bisect # initializing the list, element numbers = [10, ... Read More

2K+ Views
In this article, we are going to learn how to intersect two dictionaries using keys. We have to create a new dictionary with common keys. Let's see an example.Input: dict_1 = {'A': 1, 'B': 2, 'C': 3} dict_2 = {'A': 1, 'C': 4, 'D': 5} Output: {'A': 1, 'C': 3}We are going to use the dictionary comprehension to solve the problem. Follow the below steps to write the code.Initialize dictionaries.Iterate over the dictionary one and add elements that are not in dictionary two.Print the result.Example Live Demo# initializing the dictionaries dict_1 = {'A': 1, 'B': 2, 'C': 3} dict_2 = ... Read More