sudhir sharma

sudhir sharma

975 Articles Published

Articles by sudhir sharma

Page 87 of 98

Find the first maximum length even word from a string in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 946 Views

In this problem, we are a string str consisting of comma separated words. Our task is to find the first maximum length, even word, from a string.We need to find the largest word 'string between two spaces' whose length is maximum and even.Let's take an example to understand the problem, Input : str = "learn programming at TutorialsPoint" Output : TutorialsPointExplanation −The string with even length is TutorialsPoint. Solution ApproachA simple solution to the problem is by simply finding the string which has even length greater than the current string. Initialise the maxString length to 0.AlgorithamStep 1 − Iterate over ...

Read More

Find the Deepest Node in a Binary Tree in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 789 Views

In this problem, we are given a binary tree. Our task is to find the Deepest Node in a Binary Tree.Binary Tree is a special data structure used for data storage purposes. A binary tree has a special condition that each node can have a maximum of two children.Deepest node in a binary tree is the node which is at the maximum possible height in the tree.Let's take an example to understand the problem, Input :Output : 8Solution ApproachThere can be multiple ways to solve this problem, as you need to find the height and traverse the tree to the ...

Read More

Find the average of first N natural numbers in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 1K+ Views

In this problem, we are given a number n. Our task is to find the average of first N natural numbers.Average of numbers is defined as the sum of all numbers divided by the total number of numbers.Average of N natural numbers is defined as the sum of first N natural numbers divided by N.Let's take an example to understand the problem, Input : N = 23 Output : 12Explanation −1 + 2 + 3 + ... + 22 + 23 = 276 276 / 23 = 12Solution ApproachTo find the average of the number we will use the formula ...

Read More

Find the arrangement of queue at given time in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 259 Views

In this problem, we are given a string consisting of characters 'M' and 'F' only and a time t. Our task is to find the arrangement of the queue at a given time.The string defines people standing in a common queue to enter the bus. All males in the queue are so chivalrous that if they see a female behind them at any point of time they exchange places with them. There is t unit time left to enter the bus and each exchange takes one unit time. We need to find the positions when the bus comes by rearranging ...

Read More

Find the area and perimeter of right triangle in PL/SQL

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 1K+ Views

In this problem, we are given three values: base, height and hypotenuse of a right triangle. Our task is to find the area and perimeter of the right triangle in PL/SQL.PL/SQL is a combination of SQL along with the procedural features of programming languagesLet's take an example to understand the problem, Input : height = 4, base = 3, hypotenuse = 5 Output : area = 6, perimeter = 12Explanation −1 + 22 + 333 + 4444 = 4800 Solution ApproachA simple approach to solve the problem is using the formula for the area and perimeter of the triangle.Area = ...

Read More

Find sum of the series 1+22+333+4444+... upto n terms in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 642 Views

In this problem, we are given an integer value N. Our task is to find Sum of Series 1 + 22 + 333 + 4444 + 55555... upto n terms.Let's take an example to understand the problem, Input : N = 4 Output : 4800Explanation −1 + 22 + 333 + 4444 = 4800 Solution ApproachA simple approach to solve the problem is finding the general term of the series and then finding the sum till n terms. And calculating the sum using formula will reduce the time to O(1).The series is, 1 + 22 + 333 + 4444 + ...

Read More

Find sum of the series ?3 + ?12 +.... upto N terms in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 196 Views

In this problem, we are given an integer value N. Our task is to find Sum of Series ?3 + ?12 + ... upto n terms.The series is $\sqrt3 + \sqrt12 + \sqrt27 + \sqrt48 + ...$I.e. It is a series of square roots.Let's take an example to understand the problem, Input : N = 3 Output : 10.3922Explanation −$\sqrt3 + \sqrt12 + \sqrt27 = 1.7320 + 3.4641 + 5.1961 = 10.3922$Solution ApproachA simple approach to solve the problem is finding the general term of the series and then finding the sum till n terms. And calculating the sum using ...

Read More

Find sum of Series with n-th term as n^2 - (n-1)^2 in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 458 Views

In this problem, we are given an integer value N. Our task is to find Sum of Series n^2 - (n-1)^2 upto n terms.Let's take an example to understand the problem, Input : N = 3 Output : 6Explanation −[12 - (0)2] + [22 - (1)2] + [32 - (2)2] = 1 - 0 + 4 - 1 + 9 - 2 = 9Solution ApproachA simple approach to solve the problem is finding the general term of the series and then finding the sum till n terms. And calculating the sum using formula will reduce the time to O(1). Also, ...

Read More

Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ... upto n terms in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 1K+ Views

In this problem, we are given an integer value N. Our task is to find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ... upto n terms.Let's take an example to understand the problem, Input : N = 3 Output : 6Explanation −12 - 22 + 32 = 1 - 4 + 9 = 6Solution ApproachA simple approach to solve the problem is using loops. We will loop from 1 to n with iterator i.If i is odd, add (i2) to the sum.If i is even, subtract (i2) to the sum. At last, return the sum of series ...

Read More

Find Sum of pair from two arrays with maximum sum in C++

sudhir sharma
sudhir sharma
Updated on 27-Jan-2022 347 Views

In this problem, we are given two arrays, positive and distinct. Our task is to find the sum of pairs from two arrays with maximum sum.We will find the pair with the maximum sum with one element from each array.Let's take an example to understand the problem, Input : arr1[] = {3, 7, 5}, arr2[] = {8, 2, 4} Output : 15Explanation −Pairs is (7, 8) = 7 + 8 = 15 Solution ApproachA simple approach to solve the problem is using loops. We will use a nested loop and find the sum of all pairs and return the pair ...

Read More
Showing 861–870 of 975 articles
« Prev 1 85 86 87 88 89 98 Next »
Advertisements