Find Minimum Possible Unlancedness of Generated String in C++

Arnab Chakraborty
Updated on 25-Feb-2022 12:36:39

163 Views

Suppose we have a string S with possible characters '0', '1' or '?'. We want to make string T by replacing each occurrence of '?' with 0 or 1. The unbalancedness of T is like: maximum of the all absolute differences between number of occurrences of 0 and 1 in between lth and rth character in S where 0 1; if (check(S, Mid)) R = Mid - 1; else L = Mid + 1; } return R + 1; } int main() { string S = "0??0"; cout

Find Maximum Rated Parts Set in C++

Arnab Chakraborty
Updated on 25-Feb-2022 12:28:29

163 Views

Suppose, there is a manufacturer that makes specific parts for a particular product. The manufacturer has n different variations of the parts, and the parts have a specific rating on three criteria. The ratings of the n products are given in the array 'ratings' where each element is of the format (A, B, C) where A, B, and C are different rating criteria of the product. Now, an OEM wants to buy m parts for each product they make from the manufacturer of the parts. The OEM chooses the parts satisfying the below conditions −Two or more units of the ... Read More

C++ Program to Determine Round Trip Possibility from a City

Arnab Chakraborty
Updated on 25-Feb-2022 11:53:13

542 Views

Suppose, there are n cities and m roads are connecting them. Each road is unidirectional, and it takes a particular amount of time to reach from the source city to the destination city. The information of the roads is given in the array roads where each element is of the format (source, destination, time). Now, a person is traveling from one city to another city and the trip has to be a round-trip. A trip can be called round-trip when the person starts from a particular city, goes through one or more roads, and finishes the trip in the same ... Read More

Find Maximum Value of i in C++ Program

Arnab Chakraborty
Updated on 25-Feb-2022 11:41:05

202 Views

Suppose, we have a permutation of integers 'seq' and an array of integer pairs 'pairs' of size m that contains integers 0 to n - 1. Now, we perform the following operation on seq as many times as possible so that seq[i] = i (0 ≤ i < n) is maximized.We have to choose an integer j where 0

Find Number of Coordinate Pairs in C++

Arnab Chakraborty
Updated on 25-Feb-2022 11:29:45

1K+ Views

Suppose, we are given 2n number of coordinates on a two-dimensional plane. The 2n coordinates are divided into two arrays coordA, and coordB. The coordinates are represented as integer pairs. Now we have to form coordinate pairs that will contain one point from coordA and one point from coordB. We can make pairs if and only if the x coordinate of the point from coordA is smaller than that of the point from coordB, and the y coordinate of the point from coordA is smaller than that of the point from coordB. We have to find out the number of ... Read More

Find Maximum Sum of a Minimally Connected Graph in C++

Arnab Chakraborty
Updated on 25-Feb-2022 11:18:57

262 Views

Suppose, we are given a minimally connected graph. That means removing any edge will make the graph disconnected. The graph has n vertices and the edges are given in an array 'edges'. There is also an array 'vertexValues' given to us that contain n integer values.Now, we do the following −We write a positive integer on each of the vertices and then try to calculate a score.There is an edge connecting two vertices, we put the smaller value of the two vertices on the edges.We calculate the score by adding all the edge values.We have to find the maximum value ... Read More

Print Mirror Upper Star Triangle Pattern in Java

AmitDiwan
Updated on 25-Feb-2022 11:10:15

500 Views

In this article, we will understand how to print mirror upper star triangle pattern. The pattern is formed by using multiple for-loops and print statements.Below is a demonstration of the same −InputSuppose our input is −Enter the number of rows : 8OutputThe desired output would be −The mirror upper star pattern : ******** ******* ****** ***** **** *** ** *AlgorithmStep 1 - START Step 2 - Declare four integer values namely i, ... Read More

Calculate Cost to Travel Given Coordinates in C++

Arnab Chakraborty
Updated on 25-Feb-2022 11:07:24

274 Views

Suppose, we are given n three-dimensional coordinates. The cost to travel from coordinate (a, b, c) to (x, y, z) is ∣ x − a∣ + ∣ y − b∣ + max(0, z − c). We start from the first coordinate, then visit all the coordinates at least once, and then return to the first coordinate. We have to find out the total cost of this whole trip. The coordinates are given to us in the array 'coords'.So, if the input is like n = 3, coords = {{1, 1, 0}, {1, 3, 4}, {3, 2, 2}}, then the output ... Read More

Find Number of Jumps for Robot to Reach Cell in Grid

Arnab Chakraborty
Updated on 25-Feb-2022 10:46:30

268 Views

Suppose, we have a grid of dimensions h x w. The grid is represented in a 2D array called ‘initGrid’, where each cell in the grid is either represented by a '#' or a '.'. '#' means that the grid contains an obstacle and '.' means that there is a path through that cell. Now, a robot is placed on a cell 'c' on the grid having row number x and column number y. The robot has to travel to another cell 'd' having row number p and column number q. Both the cell coordinates c and d are presented ... Read More

Volume of Conductor Material in Underground Two-Phase AC System

Manish Kumar Saini
Updated on 25-Feb-2022 10:37:24

586 Views

When the two-phase AC electrical power is transmitted through the underground cables from the generating station to the consumers, then the transmission system is called the underground two-phase AC system of transmission.Depending upon the number of conductors used, the underground two-phase AC system is classified into two types viz −Two-phase three-Wire AC SystemTwo-phase four-wire AC SystemConductor Material Required in Underground Two-Phase Three-Wire AC SystemFigure-1 shows the circuit diagram of the underground two-phase three-wire AC system of electric power transmission.Let us consider that the maximum voltage between the outer conductors is $\mathit{V_{\mathit{m}}}$. Then, the maximum voltage between any one outer wire ... Read More

Advertisements