C++ Articles

Page 70 of 597

Fermat's Last Theorem in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 290 Views

Fermat’s last theorem in number theory also known as Fermet’s conjecture is a theorem that states that for power n greater than 2. No three values a, b, c satisfy −          an + bn = cni.e.     if n 32 + 42 = 9 + 16 = 25 = 52. 5, 12, 13 => 25 + 49 = 169 = 132.In this problem, we are given three values, L, R, pow denoting range [L, R] and power. Our task is to verify the fermat’s last theorem for the given range and power.Let’s take an example to understand the problem, ...

Read More

Fifth root of a number in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 1K+ Views

In this problem, we are given a number N. Our task is to find the floor value of the fifth root of a number.Fifth Root of a number is the number which when multiplied to itself 5 times returns the number.If N1/5 = a then, a*a*a*a*a = N.Let’s take an example to understand the problem, Input: N = 325Output: 3Explanation:  The fifth root of 325 is 3.179 whose floor value is 3.Solution Approach: A simple solution to the problem is traversing from 1 to n. And finding the number which when multiplied to itself five times gives the number.Here, the exact value cannot be found ...

Read More

Fill array with 1's using minimum iterations of filling neighbors in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 269 Views

 In this problem, we are given an array arr consisting of n elements that are either 0 or 1. Our task is to fill array with 1’s using minimum iterations of filling neighbors. Let’s take an example to understand the problem, Input: arr[] = {0, 1, 1, 0, 0, 1}Output: 1Solution Approach −To solve the problem, we need to know the fact that if 1 is present in a position it can convert two neighbouring 0’s to 1.If,                arr[i] is 1.Then,           arr[i-1] and arr[i+1] will be converted to 1.Using this, the ...

Read More

Find if given number is sum of first n natural numbers in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 443 Views

In this problem, we are given a number num. Our task is to find if the given number is the sum of first n natural numbers.  Problem Description: Here, we need to check whether the given number is the sum of first n natural numbers.Let’s take an example to understand the problem, Input: num = 55Output: yes, 10Explanation:55 is the sum of the first 10 natural numbers, 1+2+3+4+5+6+7+8+9+10.Solution Approach: A simple approach to solving the problem is finding the sum of n natural numbers until it becomes equal to or greater than num.If the sum is equal to num, return n.If at any value of ...

Read More

Find if k bookings possible with given arrival and departure times in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 377 Views

In this problem, we are given two arrays  consisting of N values denoting arrival and departure at hotel and an integer k. Our task is to find if k bookings are possible with given arrival and departure times. Problem Description: Here, we need to check if the hotel with k rooms is able to accommodate all arrivals and departures.Let’s take an example to understand the problem, Input:         Arrivals :     {1 4 5 7}Departures : {3 5 6 9}             K = 1Output: YesSolution approach:To solve the problem, we will store arrival and departure for ...

Read More

Find if there is a pair in root to a leaf path with sum equals to root's data in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 185 Views

In this problem, we are given a Binary Tree. And we need to find if there is a pair in root to a leaf path with sum equals to root’s data. We need to check if there exists a pair of nodes that lies between root node to leaf nodes such that the sum of values of pairs is equal to the root node’s value.Let’s take an example to understand the problem,   Input:Output: YesExplanation: Root node value 7Pairs with sum value equal to root node, (2, 5), (1, 6).Solution Approach: We need to traverse the tree and find the pairs using hashing.For this we ...

Read More

Find index of an extra element present in one sorted array in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 796 Views

In this problem, we are given two sorted arrays arr1 and arr2 of size n  and n+1 with all elements the same except the extra element. Our task is to find index of an extra element present in one sorted array. Problem Description: We need to find the index of an element from the n+1 size array which is not present in an array of size n.Let’s take an example to understand the problem, Input:         arr1[n]  = {3, 5, 7, 8, 9, 12}                   arr2[n+1] = {3, 4, 5, 7, 8, 9, ...

Read More

Find integers that divides maximum number of elements of the array in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 477 Views

In this problem, we are given an array arr[] of n integers.Our task is to find integers that divides maximum number of elements of the array. Problem Description: We need to find a number p which can divide the maximum number of elements of the array. In case, there are more than one such element we will return the smaller one.Let’s take an example to understand the problem,  Input: arr[] = {4, 5, 6, 7, 8}Output: 2Explanation: The element 2 divides {4, 6, 8}.Solution ApproachA simple solution to the problem is by looping through the array and then for each element of the array, divide each ...

Read More

Find largest sum of digits in all divisors of n in C++

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 268 Views

In this problem, we are given an integer n. Our task is to find the largest sum of digits in all divisors of n. Problem  Description: Here, we will find the divisor of the number n whose sum of digits in largest.Let’s take an example to understand the problem,  Input: 18Output: 9Explanation: All divisors of 18 are 1, 2, 3, 6, 9, 18.The maximum digits sum is 9.Solution ApproachFind all divisors of the number N. And then find the sum of digits of each divisors and then return the value with the largest sum.Program to illustrate the working of our solution, Example#include using namespace ...

Read More

Synonymous Sentences in C++

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

Suppose we have a list of pairs of equivalent words synonyms and a sentence text, we have to find all possible synonymous sentences they are sorted lexicographically.So, if the input is like synonyms = [["happy", "joy"], ["sad", "sorrow"], ["joy", "cheerful"]], and text = "I am happy today but was sad yesterday", then the output will be ["I am cheerful today but was sad yesterday", "I am cheerful today but was sorrow yesterday", "I am happy today but was sad yesterday", "I am happy today but was sorrow yesterday", "I am joy today but was sad yesterday", "I am joy today ...

Read More
Showing 691–700 of 5,962 articles
« Prev 1 68 69 70 71 72 597 Next »
Advertisements