C++ Articles

Page 126 of 597

Maximum value with the choice of either dividing or considering as it is in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 162 Views

In this tutorial, we will be discussing a program to find maximum value with the choice of either dividing or considering as it is.For this we will be provided with an integer value. Our task is to find the maximum value with either by dividing the number into four parts recursively or choosing it as it is using the given function F(n) = max( (F(n/2) + F(n/3) + F(n/4) + F(n/5)), n).Example#include using namespace std; //calculating the maximum result int findMaximum(int size) {    int term[size + 1];    term[0] = 0;    term[1] = 1;    int i=2;    while(i

Read More

Find Jobs involved in Weighted Job Scheduling in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 300 Views

Suppose we have a list of N jobs where each job has three parameters. 1. Start Time 2. Finish Time 3. Profit We have to find a subset of jobs associated with maximum profit so that no two jobs in the subset overlap.So, if the input is like N = 4 and J = {{2, 3, 55},{4, 6, 25},{7, 20, 150},{3, 150, 250}} , then the output will be [(2, 3, 55),(3, 150, 250)] and optimal profit 305To solve this, we will follow these steps −Define a function find_no_conflict(), this will take an array jobs, index,left := 0, right := index - 1while left

Read More

Find k-th smallest element in BST (Order Statistics in BST) in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 634 Views

Suppose we have a binary search tree and a value K as input, we have to find K-th smallest element in the tree.So, if the input is likek = 3, then the output will be 15.To solve this, we will follow these steps −Define a function find_kth_smallest(), this will take root, count, k, if root is NULL, then −return NULLleft = find_kth_smallest(left of root, count, k)if left is not NULL, then −return left(increase count by 1)if count is same as k, then −return rootreturn find_kth_smallest(right of root, count, k)From the main method, do the following −count := 0res = find_kth_smallest(root, ...

Read More

Queries for characters in a repeated string in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 255 Views

In this problem, we are given a string str and Q queries consisting of two values a and b. Our task is to create a program to solve Queries for characters in a repeated string in C++.Problem DescriptionTo solve each query, we need to check whether the characters at index a and b are the same and return the value accordingly.Let’s take an example to understand the problem, Input: str = “tutorialspoint”Q = 2Query = {{0, 2}, {4, 7}}Output:RepeatedNot RepeatedExplanationFor Query 1, the character at index 0 is t, and the character at index 2 is t. Both are the ...

Read More

Find longest bitonic sequence such that increasing and decreasing parts are from two different arrays in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 249 Views

ConceptWith respect of given two arrays, our task to determine the longest possible bitonic sequence so that increasing part must be from first array and should be a subsequence of first array. In the same way, decreasing part of must be from second array and should be a subsequence of it.Inputarr1[] = {2, 6, 3, 5, 4, 6}, arr2[] = {9, 7, 5, 8, 4, 3}Output2, 3, 4, 6, 9, 7, 5, 4, 3Inputarr1[] = {3, 1, 2, 4, 5}, arr2[] = {6, 4, 3, 2}Output1, 2, 4, 5, 6, 4, 3, 2MethodSo the concept is to implement longest increasing ...

Read More

Maximums from array when the maximum decrements after every access in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 158 Views

In this problem, we are given an array arr[]and an integer M. Our task is to create a program to find Maximums from array when the maximum decrements after every access in C++.Problem DescriptionTo find the maximum, we will find the maximum element from the array and after every retrieval and decrease it by -1, M times.Let’s take an example to understand the problem, Input: arr[] = {3, 6, 8, 9} M = 2Ouput:17Explanation1st iteration, maximum = 9, sum = 9, updated arr = {3, 6, 8, 8}2nd iteration, maximum = 8, sum = 9+8 = 17, updated arr = ...

Read More

Find longest palindrome formed by removing or shuffling chars from string in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 261 Views

ConceptWith respect of a given string, determine the longest palindrome that can be formed by removing or shuffling characters from the string. Finally return only one palindrome if it hasbeen observed that there is multiple palindrome strings of longest length.InputpqrOutputp OR q OR rInputppqqrrOutputpqrrqp OR qprrpq OR rqppqr OR any other palindromic string of length 6.InputpqpOutputpqpMethodHere, We can partition any palindromic string into three parts – beg, mid and end. With respectof palindromic string of odd length say 2n + 1, here ‘beg’ consists of first n characters of the string, ‘mid’ consists of only 1 character that means (n ...

Read More

Rotation of a point about another point in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 1K+ Views

Rotation of a point X about origin is by an angle θ in anti-clockwise direction is done by − X by θ about origin anti-clRotateockwise: X*polar( 1.0, θ ).Here, the function polar for complex numbers is defined under header file and is used to find a complex number using phase angle and magnitude. polar(mag, angle) returns a complex number.Rotation of point X about a point YTo rotate a point about another point, we will use translation in which movement of all coordinates occur in a particular direction.Steps to rotate X about Y.Translate X to Y, so Y becomes the new ...

Read More

Find lost element from a duplicated array in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 226 Views

ConceptWith respect of given two arrays which are duplicates of each other except one element, that means one element from one of the array is missing, our task to determine that missing element.Inputarr1[] = {2, 5, 6, 8, 10} arr2[] = {5, 6, 8, 10}Output22 is missing from second array.Inputarr1[] = {3, 4, 5, 6} arr2[] = {3, 4, 5, 6, 7}Output77 is missing from first array.MethodHere, we apply one simple solution where we iterate over arrays and verify element by element and mark the missing element when an unmatched is detected. But the drawback of this solution is that ...

Read More

round() in C++.

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 16K+ Views

The round() function in C++ is used to round off the double, float or long double value passed to it as a parameter to the nearest integral value. The header file used to use the round() function in a c++ program is or .Following are the overloaded versions of round() after C++ 11 standarddouble round( double D )float round( float F )long double round( long double LD )double round ( T var )Note − The value returned is the nearest integer represented as floating point, i.e for 2.3 nearest value returned will be 2.0 and not 2.Following program is ...

Read More
Showing 1251–1260 of 5,962 articles
« Prev 1 124 125 126 127 128 597 Next »
Advertisements