
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 26504 Articles for Server Side Programming

6K+ Views
Suppose we have to display a binary tree in an m*n 2D string array based on these rules −The row number m should be same as the height of the given binary tree.The column number n should be always an odd number.The value of the root node should be put in the exactly middle of the first row it can be put. The column and the row where the root node resides, will separate the rest space into two parts. These are left-bottom part and right-bottom part. We should print the left subtree in the left-bottom part and print the ... Read More

140 Views
Suppose we have a binary tree. We have to find all duplicate subtrees. So for each kind of duplicate subtrees, we have to return the root node of any one of them. So suppose we have a tree like −The duplicate subtrees are −To solve this, we will follow these steps −Create an array ret, make a map mDefine a recursive method solve(). This will take node as input. This works as −if node is null, then return -1x := value of node as string, then concatenate “#” with it.left := solve(left of node), right := solve(right of node)x := ... Read More

604 Views
Suppose we have an array consists of non-negative integers, our task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle. So if the input is like [2, 2, 3, 4], then the result will be 3 as [2, 3, 4] using first 2, [2, 3, 4] using second 2, and [2, 2, 3].To solve this, we will follow these steps −ret := 0, n := size of nums, sort numsfor i in range n – 1 down to 0right := i – 1, left ... Read More

293 Views
Sometimes we need to find the differences between two lists. It will also mean a mathematical subtraction in which the elements from the first list are removed if they are present in the second list. Duplicates are preserved. Below is the approach through which we can achieve this.We can use the Counter method from the collections module which will keep track of the count of elements. A straight mathematical subtraction gives the desired result. In the final result the number of occurrences of an element between the first and the second list will decide the elements.Example Live Demofrom collections import Counter ... Read More

841 Views
In this article we will learn how to create a dictionary from another frequently used python collection namely list. An index or key is not part a list content. But in dictionary we need to have a key or index attached to every element which is referred as value.Using enumerateThe enumerate function adds a counter as the key of the enumerate object. SO we apply it to a given list and using a for loop. That creates the required dictionary where the keys are generated by the enumerate function.Example Live DemoAlist = ['Mon', 'Tue', 'Wed', 'Wed', 11, 11] # Given ... Read More

540 Views
Suppose we have a zero-indexed array A of length N that contains all integers from 0 to N-1. We have to find and return the longest length of set S, where S[i] = {A[i], A[A[i]], A[A[A[i]]], ... } subjected to the rule below. Now consider the first element in S starts with the selection of element A[i] of index = i, the next element in S should be A[A[i]], and then A[A[A[i]]]… By that analogy, we stop adding right before a duplicate element occurs in S. So if the array is like A = [5, 4, 0, 3, 1, 6, ... Read More

484 Views
ging the collection type from one type to another is a very frequent need in python. In this article we will see how we create a tuple from the key value pairs that are present in a dictionary. Each of the key value pair becomes a tuple. So the final list is a list whose elements are tuples.With items()We sue the items method of the dictionary which allows us to iterate through each of the key value pairs. Then we use a for loop to pack those values in to a tuple. We put all these tuples to a final ... Read More

178 Views
Changing the collection type from one type to another is a very frequent need in python. In this article we will see how we create a dictionary when multiple lists are given. The challenge is to be able to combine all these lists to create one dictionary accommodating all these values in a dictionary key value format.With zipThe zip function can be used to combine the values of different lists as shown below. In the below example we have taken three lists as input and combine them to form a single dictionary. One of the list supplies the keys for ... Read More

499 Views
A python dictionary is a collection which is unordered, changeable and indexed. They have keys and values and each item is referred using the key. In this article we will explore the ways to delete the items form a dictionary.Using del with keysIn this approach we capture the key values that are needed to be deleted. Once we apply the del function, the key value pairs for those keys get deleted.Example Live Demo# Given dictionary ADict = {1: 'Mon', 2: 'Tue', 3: 'Wed', 4:'Thu', 5:'Fri'} # Get keys with value in 2, 3. to_del = [key for key in ADict ... Read More

257 Views
Suppose we have a positive 32-bit integer n, we need to find the smallest 32-bit integer which has exactly the same digits existing in the integer n and is greater in value than n. If we have no such positive 32-bit integer number, then return -1.So if the number is 213, then the result will be 231.To solve this, we will follow these steps −s := n as string, sz := size of s, ok := falsefor i in range sz – 2 to 0if s[i] < s[i + 1], then ok := true and break the loopif of is ... Read More