Programming Articles

Page 222 of 2545

Program to Find Out Median of an Integer Array in C++

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

Suppose we have to implement a class named MedianClass which contains the following methods −add(value) which adds a value to the data structure.median() finds the median of all the numbers currently present in the data structure.So, if we add 5, 3, 8 and find median, the output will be 5.0, then if we add 9 and find the median, the output will be 6.5.To solve this, we will follow these steps −Define priority queue left and rightDefine addNum method, this will take the number as input −if left is empty or num < top element of left, then, insert num ...

Read More

Check if it is possible to create a palindrome string from given N in Python

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

Suppose we have a number n. We have to check whether we can create an alphabetical lowercase string from that number and check whether the string is palindrome or not. Here we will take only characters from a to j, [a = 0, b = 1... j = 9]. So if the number is 42 the substring "ec" will be printed till 6 (4+2) characters "ececec" then check this is palindrome or not.So, if the input is like n = 43, then the output will be True the string is "ededede" and this is palindrome.To solve this, we will follow ...

Read More

Find largest number smaller than N with same set of digits in C++

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

In this problem, we are given a string N that represents a number. Our task is to find the largest number smaller than N with the same set of digits.  Problem Description: we need to find a number using all the digits of the given number which is the largest smaller number than N.Let’s take an example to understand the problem,  Input: N = “54314”Output: 54341Solution ApproachA simple solution to the problem is by finding the digit of the number which can be moved to find the largest smaller number. Now, the number should be greater than its right success in order to solve ...

Read More

Program to Find Out the Smallest Substring Containing a Specific String in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Suppose we have two strings s and t. We have to find the smallest substring in s, where t is also a subsequence of the substring. If that type of substring does not exist, we will return a blank string, and if there are multiple smallest substrings, we will take the leftmost one.So, if the input is like s = "abcbfbghfb", t = "fg", then the output will be fbgTo solve this, we will follow these steps −N := size of Sdp := a new list of size N initialized with infinityfor i in range 0 to N − 1, ...

Read More

Count of Binary Digit numbers smaller than N in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 349 Views

Given an integer N as input. The goal is to find the count of integers that are less than N and represented in Binary form. For example if input N is 12 then numbers less than 12 are 1, 10, 11 that are binary and contain 0s and 1s as digits. The answer would be 3.For ExampleInputN=100OutputCount of Binary Digit numbers smaller than N are − 4ExplanationThe Binary numbers less than 100 are − 1, 10, 11, 100InputN=120OutputCount of Binary Digit numbers smaller than N are: 7ExplanationThe Binary numbers less than 100 are : 1, 10, 11, 100, 101, 110, ...

Read More

Check if it is possible to create a polygon with a given angle in Python

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

Suppose we have an angle a. We have to check whether we can make a regular polygon where all angles are same as a or not.So, if the input is like a = 120, then the output will be True the pentagon has all angles same as 120°. As we know$$Interior Angle(a)=\frac{180\times(n-2)}{n}\begin{bmatrix} n=number of sides of polygon\end{bmatrix}$$ $$¿n=\frac{360}{180-a}$$So if n is integer then this is forming a regular polygon.To solve this, we will follow these steps −sides := 360 /(180 - a)if sides has no fractional part, thenreturn Truereturn FalseExampleLet us see the following implementation to get better understanding −def ...

Read More

Find largest subtree sum in a tree in C++

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

In this problem, we are given a binary tree. Our task is to find the largest subtree sum in a tree. Problem Description: The  binary tree consists of positive as well as negative values. And we need to find the subtree that has the maximum sum of nodes.Let’s take an example to understand the problem,  Output: 13Explanation: The sum of left-subtree is 7The sum of right-subtree is 1The sum of tree is 13Solution ApproachTo solve the problem, we will do the post-order traversal. Calculate sum of nodes left subtree and right subtree. For current node, check if the sum of nodes of current node ...

Read More

Count the number of intervals in which a given value lies in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 484 Views

Given a 2D array arr[][] containing intervals and a number ‘value’. The goal is to find the number of intervals present in arr between which value lies. For example intervals are [ [1, 5], [3, 7] ] and value=4 then it lies in both these intervals and count would be 2.For ExampleInputarr[4][2] = { { 1, 20 }, { 12, 25 }, { 32, 40 }, { 15, 18 } } value=16OutputCount of number of intervals in which a given value lies are: 3ExplanationThe value 16 lies between 1−20, 12−25 and 15−18Inputarr[4][2] = {{ 1, 20 }, { 20, 30 ...

Read More

Check if it is possible to create a polygon with given n sidess in Python

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

Suppose we have an array nums that contain the size of n sides. We have to check whether we can form a polygon with all of the given sides or not.So, if the input is like nums = [3, 4, 5], then the output will be True because there are three sides and sum of any two sides is larger than the 3rd one. To solve this, we will use this property where length of one side is smaller than the sum of all other sides.To solve this, we will follow these steps −sort the list numsif last element of ...

Read More

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

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 256 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
Showing 2211–2220 of 25,445 articles
« Prev 1 220 221 222 223 224 2545 Next »
Advertisements