
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

3K+ Views
Suppose we have an unsorted list of integers. We have to find the longest increasing subsequence. So if the input is [10, 9, 2, 5, 3, 7, 101, 18], then the output will be 4, as the increasing subsequence is [2, 3, 7, 101]To solve this, we will follow these steps −trail := an array of length 0 to length of nums – 1, and fill this with 0size := 0for x in numsi := 0, j := sizewhile i is not jmid := i + (j - i) / 2if trails[mid] < x, then i := mid + 1, ... Read More

3K+ Views
Suppose we have an array nums containing n + 1 integers. The members are in range 1 to n. prove that at least one duplicate number must be there. Assume that there is only one duplicate number, we have to find that duplicate element. So if the array is like [1, 3, 4, 2, 2], then the duplicate element will be 2.To solve this, we will follow these steps −a := nums[0] and b := nums[0]while Truea := nums[nums[a]]b := nums[b]if a = b, then breakptr := nums[0]while ptr is not bptr := nums[ptr]b := nums[b]return ptrLet us see the ... Read More

636 Views
Suppose we have one m x n matrix. We have to write an efficient algorithm that searches for a value in that matrix. This matrix has the following properties −Integers in each row are sorted in ascending from left to right.Integers in each column are sorted in ascending from top to bottom.So if the matrix is like −14711152581219369162210131417241821232630If target is 5, then return true, if target is 20, then return falseTo solve this, we will follow these steps −len := number of columns, c1 := 0, c2 := len – 1while trueif matrix[c1, c2] = target, then return trueelse ... Read More

1K+ Views
Suppose we have an array called nums of n integers where n > 1. We have to find an array output such that output[i] is equal to the product of all the elements of nums except nums[i]. So if the input array is [1, 2, 3, 4], then the output will be [24, 12, 8, 6]. We have to solve this without using division operator.To solve this, we will follow these steps −right_mul := an array of size same as nums, fill it with 0last element of right_mul = last element of numsfor i in range 1 to length of ... Read More

1K+ Views
Suppose we have a binary tree. we have to find the Lowest common ancestor nodes of two given nodes. The LCA of two nodes p and q is actually as the lowest node in tree that has both p and q as decedent. So if the binary tree is like [3, 5, 1, 6, 2, 0, 8, null, null, 7, 4]. The tree will be like −Here LCA of 5 and 1 is 3To solve this, we will follow these steps −If the tree is empty, then return nullif p and q both are same as root, then return rootleft ... Read More

1K+ Views
Suppose we have a binary search tree. We have to find the Kth smallest element in that BST. So if the tree is like −So if we want to find 3rd smallest element, then k = 3, and result will be 7.To solve this, we will follow these steps −create one empty list called nodescall solve(root, nodes)return k – 1th element of nodesthe solve method is created, this takes root and nodes array, this will work as follows −if root is null, then returnsolve(left of root, nodes)add value of root into the nodes arraysolve(right of root, nodes)Let us see the ... Read More

2K+ Views
Suppose we have an unsorted array, we have to find the kth largest element from that array. So if the array is [3, 2, 1, 5, 6, 4] and k = 2, then the result will be 5.To solve this, we will follow these steps −We will sort the element, if the k is 1, then return last element, otherwise return array[n – k], where n is the size of the array.Let us see the following implementation to get better understanding −Example Live Democlass Solution(object): def findKthLargest(self, nums, k): nums.sort() if k ==1: ... Read More

5K+ Views
Suppose we have to make the trie structure, with three basic operations like insert(), search(), startsWith() methods. We can assume that all inputs are in lowercase letters. For example, if we call the functions as follows, we will see the outputsTrie trie = new Trie()trie.insert(“apple”)trie.search(“apple”) //This will return truetrie.search(“app”) //This will return falsetrie.startsWith(“app”) //This will return truetrie.insert(“app”)trie.search(“app”) //This will return trueTo solve this, we will follow these steps −Initially make one dictionary called child.The insert method will be like −current := childfor each letter l in word −if l is not present in ... Read More

2K+ Views
Suppose we have a grid, there are few 0s and few 1s. We have to count the number of islands. An island is place that is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. We can assume that all four edges of the grid are all surrounded by water.Suppose the grid is like −11000110000010000011There are three islands.To solve this, we will follow these steps −There will be two methods, one will be used to count number of islands called numIslands() and makeWater(). The makeWater() will be like −if number of rows in the grid is ... Read More

4K+ Views
A peak element in an array is defined as an element that is greater than its neighbors. We can use some common approaches such as binary search to efficiently locate a peak element and linear search algorithm which involves iterating through an array. Binary Search Approach The Binary Search is an efficient technique for locating a peak element in an array. To find a peak, follow these steps: Choose the middle element of the array. ... Read More