
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

200 Views
Suppose we have an array for which the i-th element is the price of a given stock for the day i. We have to devise an algorithm to find the maximum profit. We can complete at most k transactions. So if the input is like [3, 2, 6, 4, 0, 3] and k = 2, then the output will be 7, as buy on day 2 (when price = 2) and sell on day 3 (when price = 6), profit will be 6-2 = 4. Then buy on day 5 (price is 0) and sell on day 6 (price is ... Read More

709 Views
Suppose there is a story like the demons had captured the princess whose name is P and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M row, N column grid-like rooms. Our valiant knight named K was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.Now the knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies at that moment.Some of the rooms have demons to guard that room, so the ... Read More

458 Views
Suppose we have an array, that is not sorted. We have to find the maximum difference between successive elements in its sorted form. We will return 0 if the array contains less than 2 elements. So if the array is like [12, 3, 9, 1, 17], then the output will be 6, as the sorted array will be [1, 3, 9, 12, 17] so 5 will be the maximum difference as difference between 3 and 9 is 6.To solve this, we will follow these steps −minVal := inf, maxCal := -infn := size of numsif n < 2, then return ... Read More

340 Views
Suppose we have an array that is sorted, now that is rotated at some pivot. The pivot is not known before. We have to find the minimum element from that array. So if the array is like [4, 5, 5, 5, 6, 8, 2, 3, 4], then the minimum element is 2.To solve this, we will follow these steps −Define one method called search(), this takes arr, low and highif low = high, then return arr[low]mid := low + (high – low) / 2ans := infif arr[low] < arr[mid], then ans := min of arr[low] and search(arr, mid, high)otherwise when ... Read More

591 Views
Suppose we have a 2D plane. We have to find the maximum number of points that reside on the same straight line. So if the points are like −Then there are 4 pointsTo solve this, we will follow these steps −n := number of points, if n < 3, then return nans := 2for i in range 1 to n – 1count := 0take two points from index i and i – 1, these are p1, p2if p1 and p2 points are same, thenfor j in range 0 to n – 1if points[j].x = p1.x and points[j].y = p1.y, then ... Read More

1K+ Views
Suppose we have a binary tree. We have to find the post order traversal of this tree using the iterative approach. So if the tree is like −Then the output will be: [9, 15, 7, 10, -10]To solve this, we will follow these steps −if root is null, then return empty arraycreate an array retstack := define a stack with pair [root, 0]while stack is not empty −node := top of stack, then delete element from stack.if second value of node pair is 0, thencurrent := first value of node pairinsert a pair (current, 1) into stackif right of current ... Read More

493 Views
Suppose we have a non-empty string s and a dictionary called wordDict, this dictionary is containing a list of non-empty words, add spaces in s to construct a sentence where each word is a valid dictionary word. We have to find all such possible sentences. “appleraincoat” and dictionary is [“app”, “apple”, “rain”, “coat”, “raincoat”]To solve this, we will follow these steps −Create one map memoDefine a method called solve, this will take string and wordDictif s is null, then return empty listif s in memo, then −return memo[s]create an array retfor i in range 1 to size of sif substring ... Read More

563 Views
Suppose there are N children, they are standing in a line. Here each child is assigned a rating value. We are supplying candies to these children subjected to the following requirements −Each child must have at least one candy.Children whose rating is high will get more candies than their neighbors.We have to find the minimum number of candies we must give?So if the input is like [1, 1, 3], then the output will be 4. So they will get 1, 1 and 2 candies respectively.To solve this, we will follow these steps −n := size of the array ratings, create ... Read More

178 Views
Suppose we have a string s, we have to find the number of cuts needed to divide this string into different substring and each part is a palindrome. So if the string is like “ababba”, then this will take 2 cuts. [aba|bb|a]To solve this, we will follow these steps −n := number of characters in the string screate one array called res of size n + 1res[n] := -1for i in range n – 1 down to 0res[i] := n – i – 1for j in range i to nif substring of a, from index i, to j – i ... Read More

5K+ Views
Suppose we have an array of integers. We have to find the length of the longest consecutive elements sequence. So if the input is like [100, 4, 250, 1, 3, 2], answer will be 4, as the longest consecutive sequence is [1, 2, 3, 4].To solve this, we will follow these steps −make the array set, longest := 0for i in range array −if i – 1 is not in a −current := i, streak := 0while i in a −increase i by 1, increase streak by 1longest := max of longest and streakreturn longestExampleLet us see the following implementation ... Read More