Found 26504 Articles for Server Side Programming

Minimum Cost to Hire K Workers in C++

Arnab Chakraborty
Updated on 04-Jun-2020 08:29:07

560 Views

Suppose there are N workers. Each worker has the quality parameter. The i-th worker has a quality[i] and a minimum wage expectation wage[i]. Now we want to hire K workers to form a paid group. When we are hiring a group of K workers, we must pay them according to the following rules −Each worker in the paid group should be paid in the ratio of their quality by comparing with others in the paid group.Every worker in the paid group must be paid at least their minimum wage expectation.We have to find the least amount of money needed to ... Read More

K-Similar Strings in C++

Arnab Chakraborty
Updated on 04-Jun-2020 08:24:52

301 Views

Suppose we have two strings A and B. These two strings are K-similar (where K is one nonnegative integer) if we can swap the positions of two letters in A exactly K times so that the resulting string is B. So, we have two anagrams A and B, we have to find the smallest K for which A and B are K-similar.So, if the input is like A = "abc", B = "bac", then the output will be 2.To solve this, we will follow these steps −Define a function swapp(), this will take string s, i, j, x := s[i], ... Read More

Shortest Path Visiting All Nodes in C++

Arnab Chakraborty
Updated on 04-Jun-2020 08:21:38

1K+ Views

Suppose we have one undirected, connected graph with N nodes these nodes are labeled as 0, 1, 2, ..., N-1. graph length will be N, and j is not same as i is in the list graph[i] exactly once, if and only if nodes i and j are connected. We have to find the length of the shortest path that visits every node. We can start and stop at any node, we can revisit nodes multiple times, and we can reuse edges.So, if the input is like [[1], [0, 2, 4], [1, 3, 4], [2], [1, 2]], then the output ... Read More

Similar String Groups in C++

Arnab Chakraborty
Updated on 04-Jun-2020 08:17:43

284 Views

Suppose we have two strings X and Y, these are similar if we can swap two letters of X, so that it equals Y. Also two the strings X and Y are similar if they are equal. As an example, consider, two strings are like "tars" and "rats" are similar, if we swap t and r, then we can find another, now "rats" and "arts" are similar, but "star" is not similar to "tars", "rats", or "arts". Now we can see, these form two connected groups by similarity: {"tars", "rats", "arts"} and {"star"}. Here "tars" and "arts" are in the ... Read More

Sum of Distances in Tree in C++

Arnab Chakraborty
Updated on 04-Jun-2020 08:13:41

712 Views

Suppose we have one undirected, connected tree where N nodes are present. These are labelled as 0...N-1 and N-1 edges are given. The ith edge connects nodes edges[i][0] and edges[i][1] together. We have to find a list where ans[i] is the sum of the distances between node i and all other nodes.So, if the input is like N = 6 and edges = [(0, 1), (0, 2), (2, 3), (2, 4), (2, 5)], then the output will be [8, 12, 6, 10, 10, 10]To solve this, we will follow these steps −Define a function dfs1(), this will take node, parent, ... Read More

Consecutive Numbers Sum in C++

Arnab Chakraborty
Updated on 04-Jun-2020 08:07:41

1K+ Views

Suppose we have a positive integer N, we have to find how many different ways can we write it as a sum of consecutive positive integers?So, if the input is like 10, then the output will be 3, this is because we can represent 10 as 5 + 5 and 7 + 3, so there are two different ways.To solve this, we will follow these steps −ret := 1for initialize i := 2, (increase i by 1), do −sum := (i * (i + 1)) / 2if sum > N, then −Come out from the looprem := N - sumret ... Read More

Program to find the Discount Percentage in C++

Ayush Gupta
Updated on 16-Sep-2020 08:52:02

964 Views

In this problem, we are given two numbers that define the marked price(M) and selling price(S) of a certain product. Our task is to create a program to find the Discount Percentage in C++.Discount is the amount that is deducted from the actual price (marked price) on a product.The formula for discount is, discount = marked price - selling priceDiscount percentage is the percentage of the price that is deducted from the actual price of the product.The formula for discount percentage is, discount percentage = (discount / marked price ) * 100Let’s take an example to understand the problem, Input240, ... Read More

Program to find the common ratio of three numbers in C++

Revathi Satya
Updated on 22-May-2024 11:52:10

488 Views

In this article, Our task is to create a Program to find the common ratio of three numbers in C++. The common ratio of three numbers is usually the same ratio between two numbers multiplied by each other to get the next one. When a particular number of terms in progression or sequence are involved such as in the geometric progression, a common ratio can be easily found by dividing the term with the preceding term. For instance, if we have three numbers x, y, and z. then the common ratio r can be found as r = x:y = ... Read More

Program to find the diameter, cycles and edges of a Wheel Graph in C++

Ayush Gupta
Updated on 16-Sep-2020 08:55:31

336 Views

In this problem, we are given a number that denotes the number of vertices of a Wheel Graph. Our task is to create a Program to find the diameter, cycles and edges of a Wheel Graph in C++.Problem description − Here, we need to find the number of cycles, number of edges, and the diameter of Wheel Graph with n vertices.First, let’s understand some basics about Wheel Graph −A wheel graph is obtained from a cycle graph Cn-1 by adding a new vertex. That new vertex is called a Hub which is connected to all the vertices of Cn.Example of ... Read More

Program to find the Circumcircle of any regular polygon in C++

Ayush Gupta
Updated on 16-May-2022 07:22:35

203 Views

In this problem, we are given two numbers that give the number of sides of a polygon N and the length of each side A. Our task is to create a Program to find the Circumcircle of any regular polygon in C++.Problem description − Here, we need to find the radius and area of the circumcircle of the regular polygon whose side number and length are given.Let’s take an example to understand the problem, Inputn = 4 a = 2Program to illustrate the working of our solution, Example Live Demo#include using namespace std; void CalcRadAreaCircumcircle(float n, float a) {   ... Read More

Advertisements