
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

617 Views
Suppose there is an unsorted array. We have to check whether an increasing subsequence of length 3 exists or not in that array.Formally the function should −Return true if there exists i, j, ksuch that arr[i] < arr[j] < arr[k] given 0 ≤ i < j < k ≤ n-1 else return false.To solve this, we will follow these steps −small := infinity, big := infinityfor each element i in arrayif i

720 Views
Suppose we have a singly linked list, we have to group all odd nodes together followed by the even nodes. Here we are talking about the node position not the value in the nodes. We should try to do it in place. So if the nodes are [1, 22, 13, 14, 25], the result will be [1, 13, 25, 22, 14]To solve this, we will follow these steps −if head is null or the next of head is null, then return headhead1 := head, head2 := next of head, head_beg := next of headwhile next of head2 is nor null ... Read More

167 Views
Suppose we have an array for which the ith element is the price of a given stock on the day i. We have to design an algorithm to find the maximum profit. We may complete as many transactions as we want (So, buy one and sell one share of the stock multiple times). But we have to follow these rules −We may not engage in multiple transactions at the same time (So, we must sell the stock before you buy again).After we sell our stock, we cannot buy stock on next day. (So cool down 1 day)If the input is ... Read More

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

533 Views
Suppose we have a positive integer n, find the least number of perfect square numbers whose sum is n. So if the number is 13, then the output is 2, as the numbers are 13 = 9 + 4To solve this, we will follow these steps −create one table for dynamic programming, of length n + 1, and fill it with infinitydp[0] := 0for i := 1, when i*i dp(n+1,INF); dp[0] = 0; for(int i =1;i*i

637 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