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
Server Side Programming Articles - Page 1828 of 2650
452 Views
Suppose we have an array of prices P [p1, p2..., pn] and a target value, we have to round each price Pi to Roundi(Pi) so that the rounded array [Round1(P1), Round2(P2)..., Roundn(Pn)] sums to the given target value. Here each operation Roundi(pi) could be either Floor(Pi) or Ceil(Pi).We have to return the string "-1" if the rounded array is impossible to sum to target. Otherwise, return the smallest rounding error, which will be (as a string with three places after the decimal) defined as −$\displaystyle\sum\limits_{i-1}^n |Round_{i} (???? ) - ????$So if the input is like [“0.700”, “2.800”, “4.900”], and the ... Read More
336 Views
Suppose we have a string, we can form a subsequence of that string by deleting some number of characters (possibly no deletions). So if there is two strings source and target, we have to find the minimum number of subsequences of source such that their concatenation equals target. If the task is impossible, then return -1. So if source is “abc” and target is “abcbc”, then the output will be 2.To solve this, we will follow these steps −Define a string called possible, this will take s and t as inputcreate a map mfor each character c in s mark ... Read More
1K+ Views
Suppose we have a collection of rocks, now each rock has a positive integer weight. In each turn, we choose any two rocks and smash them together. If the stones have weights x and y with x = 0, decrease j by 1dp[j] := false when (dp[j] and dp[j – stones[i]]) both are false, otherwise trueif dp[j] is true, then reach := max of reach and jreturn total – (2 * reach)Let us see the following implementation to get better understanding −Example Live Demo#include using namespace std; class Solution { public: int lastStoneWeightII(vector& stones) { ... Read More
549 Views
Suppose we have a list of words, here each word consists of lowercase letters. So one word word1 is a predecessor of another word word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2. For the example of the predecessor is like, "abc" is a predecessor of "abac". Now a word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on. We have to find the longest possible length of ... Read More
324 Views
Suppose we have an infinite plane, a robot initially stands at position (0, 0) and faces north. The robot can receive one of three instructions −G − go straight 1 unit;L − turn 90 degrees to the left direction;R − turn 90 degrees to the right direction.The robot performs the instructions given in order, Instructions are repeated forever. We have to check whether there exists a circle in the plane such that the robot never leaves the circle. So if the input is like [GGLLGG], then the answer will be true. from (0, 0) to (0, 2), it will loop ... Read More
365 Views
Suppose we have a value N, consider a convex N-sided polygon with vertices labelled A[0], A[i], ..., A[N-1] are in clockwise order. Now suppose we want to triangulate the polygon into N-2 triangles. For each triangle, the value of that triangle is the product of the labels of the vertices, and the total score of the triangulation will be the sum of these values over all N-2 triangles in the triangulation. We have to find the smallest possible total score that we can achieve with some triangulation of the polygon. So if the input is [1, 2, 3], then the ... Read More
244 Views
Suppose we have written the integers of A and B (in the order they are given) on two separate horizontal lines. Now, we may draw connecting lines: a straight line connecting two numbers A[i] and B[j] such that −A[i] == B[j];The line we draw that does not intersect any other connecting (non-horizontal) line.We have to keep in mind that connecting lines cannot intersect even at the endpoints − each number can only belong to one connecting line. Find the maximum number of connecting lines. So if the input is like [1, 4, 2] and [1, 2, 4], then the output ... Read More
283 Views
Suppose we have a series of video clips from a sporting event that lasted T seconds. Now these video clips can be overlapping with each other and have varied lengths. Here each video clip clips[i] is an interval − it starts at clips[i][0] time and ends at clips[i][1] time. We can cut these clips into segments freely − We have to find the minimum number of clips needed so that we can cut the clips into segments that cover the entire sporting event ([0, T]). If the task is impossible, return -1. So if the input is like [[0, 2], ... Read More
230 Views
Suppose we have given a 2D array A, now each cell is 0 (representing sea) or 1 (representing land) Here a move consists of walking from one land square 4-directionally to another land square, or off the boundary of the grid. We have to find the number of land squares in the grid for which we cannot walk off the boundary of the grid in any number of moves. So if the grid is like −0000101001100000The answer will be 3, as there are three ones enclosed by 0s, and one 1 is not enclosed.To solve this, we will follow these ... Read More