
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 7197 Articles for C++

805 Views
Suppose we have an array called nums, there is a sliding window of size k which is moving from the left of the array to the right. We can only see the k numbers in the window. Each time the sliding window moves to the right side by one position. We have to find the max sliding window. So if the input is like −[1, 3, -1, -3, 5, 3, 6, 8] and k is 3, then the window will be like −Window PositionMax13-1-35368313-1-35368313-1-35368313-1-35368513-1-35368613-1-353688To solve this, we will follow these steps −Define an array ansDefine one double ended queue dqif ... Read More

423 Views
Suppose we have a number n, We have to count the total number of digit 1 appearing in all non-negative numbers less than or equal to n. So if the input is 15, then the output will be 8, because the numbers containing 1 is [1,10,11,12,13,14,15], there are 8 1s.To solve this, we will follow these steps −ret := 0for initializing i := 1, when i

756 Views
Suppose we have a string s. We can convert it to palindrome by adding characters in front of it. We have to find the shortest palindrome, that we can find performing this information. So if the string is like “abcc”, then the result will be − "ccbabcc".To solve this, we will follow these steps −n := size of s, s1 := s, s2 := sReverse the string s2s2 := s concatenate "#" concatenate s2Define an array lps of size same as s2j := 0, i := 1while i < size of s2, do −if s2[i] is same as s2[j], then, ... Read More

195 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

705 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

588 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

562 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