
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++

212 Views
Suppose we have a list of n orders, in each order there are pickup and delivery services. We have to count all valid pickup/delivery possible sequences such that delivery[i] is always after the pickup[i]. As the answer may very large, we will return it modulo 10^9 + 7.So, if the input is like 2, then the output will be 6, as All possible orders are (P1, P2, D1, D2), (P1, P2, D2, D1), (P1, D1, P2, D2), (P2, P1, D1, D2), (P2, P1, D2, D1) and (P2, D2, P1, D1). And the order (P1, D2, P2, D1) is not valid ... Read More

142 Views
Suppose we have an array of integers target. From a starting array A consisting of all 1's, we can perform the following procedure −Consider x be the sum of all elements currently in our array.Choose index i, in range 0 to n, where n is the size of the array and set the value of A at index i to x.We can repeat this procedure as many times as we need.We have to check whether it is possible to make the target array from A otherwise return False.So, if the input is like [3, 9, 5], then the output will ... Read More

346 Views
Suppose we have an array of integers called arr. We are initially at index 0. In one step we can jump from index i to i + x where: i + x < n. i - x where: i - x >= 0. j where: arr[i] and arr[j] are same and i and j are not same. Here n is the size of array. We have to find the minimum number of steps to reach the last index of the array.So, if the input is like, then the output will be 3, We need three jumps from index 0 to ... Read More

622 Views
Suppose we have an array of integers called arr and an integer d. In one step we can jump from index i to −i + x where: i + x < n and x in range 1 to d.i - x where: i - x >= 0 and x in range 1 to d.Here n is the size of array. In addition, we can only jump from index i to index j when arr[i] > arr[j] and arr[i] > arr[k] for all indices k between i and j. We can choose any index of the array and start the jumping. ... Read More

369 Views
Suppose we want to schedule a list of tasks in d days. The tasks are dependent so, to work on the i-th task, we have to finish all the tasks j where 0 0, then −return 1^6if dp[idx, k] is not equal to -1, then −return dp[idx, k]maxVal := 0ret := inffor initialize i := idx, when i < size of v, update (increase i by 1), do −maxVal := maximum of v[i] and maxValret := minimum of ret and maxVal + solve(v, i + 1, k - 1, dp)dp[idx, k] := retreturn retFrom the main method do the ... Read More

542 Views
Suppose we have one integer array called nums. The value of this array is defined as the sum of |nums[i]-nums[i+1]| for all i in range 0 to n - 1. Where n is the size of the array. We can select any subarray of the given array and reverse it. We can perform this operation only once. Then we have to find the maximum possible value of the final array.So, if the input is like [1, 5, 4, 2, 3], then the output will be 10.To solve this, we will follow these steps −ret := 0, extra := 0n := ... Read More

362 Views
Suppose there is a one-dimensional garden on the x-axis. The starting position of the garden is 0, and ending position is n. There are n + 1 taps located at points [0, 1, ..., n] in the garden. If we have an integer n and an integer array ranges of length n + 1 where ranges[i] is the i-th tap can water the area [i - ranges[i], i + ranges[i]] when that area is open.We have to find the minimum number of taps that should be open to water the whole garden, if there is no possible solution, then return ... Read More

265 Views
Suppose we have a keyboard layout like below −ABCDEFGHIJKLMNOPQRSTUVWXYZWhere each English uppercase letter is located at some coordinate, as an example, the letter A is placed at (0, 0), the letter B is placed at (0, 1), the letter P is placed at (2, 3) and the letter Z is placed at (4, 1). Now if we have a word, we have to find the minimum total distance to type such string using only two fingers. The distance between two places (x1, y1) and (x2, y2) is |x1 - x2| + |y1 - y2|. And we can start from any ... Read More

171 Views
Suppose we have a string S; we have to find the number of distinct non-empty substrings of S that can be written as the concatenation of some string with itself.So, if the input is like "elloelloello", then the output will be 5, as there are some substrings like "ello", "lloe", "loel", "oell".To solve this, we will follow these steps −prime := 31m := 1^9 + 7Define a function fastPow(), this will take base, power, res := 1while power > 0, do −if power & 1 is non-zero, then −res := res * baseres := res mod mbase := base * ... Read More

490 Views
Suppose we have an equation, expressions are represented by words on left side and the result on right side. We have to check whether the equation is solvable under the following rules or not −Each character is decoded as one digit (0 to 9).Every pair of different characters must map to different digits.Each words[i] and result are decoded as a number where no leading zeros are present.Sum of numbers on left side will equal to the number on right side.We will check whether the equation is solvable or not.So, if the input is like words = ["SEND", "MORE"], result = ... Read More