Articles on Trending Technologies

Technical articles with clear explanations and examples

Maximize the maximum subarray sum after removing at most one element in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 374 Views

Problem statementGiven an array arr[] of N integers. The task is to first find the maximum sub-array sum and then remove at most one element from the sub-array. Remove at most a single element such that the maximum sum after removal is maximized.If given input array is {1, 2, 3, -2, 3} then maximum sub-array sum is {2, 3, -2, 3}. Then we can remove -2. After removing the remaining array becomes−{1, 2, 3, 3} with sum 9 which is maximum.Algorithm1. Use Kadane’s algorithm to find the maximum subarray sum. 2. Once the sum has beens find, re-apply Kadane’s algorithm ...

Read More

Maximum length of the sub-array whose first and last elements are same in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 405 Views

In this problem, we are given an array of characters. Our task is to create a program to print the maximum length of the subarray whose first and last elements are same in C++.Let’s take an example to understand the problem, Input − array = {‘t’, ‘u’, ‘t’, ‘o’, ‘r’, ‘i’, ‘a’, ‘l’, ‘s’, ‘p’, ‘o’, ‘i’, ‘n’, ‘t’ }Output − 14Explanation −The subarray {‘t’, ‘u’, ‘t’, ‘o’, ‘r’, ‘i’, ‘a’, ‘l’, ‘s’, ‘p’, ‘o’, ‘i’, ‘n’, ‘t’ } starts and ends with t.To solve this problem, we find the first and last occurrence a character in the array and ...

Read More

Height Checker in Python

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

Suppose a set of students have to be arranged in non-decreasing order of their heights for a photograph. If we have an array of students, we have to return the minimum number of students that are not present in correct position. So if the array is like [1, 1, 4, 2, 1, 3], then output will be 3. So students with height 4, 3 and the last 1 are not standing in the correct position.To solve this, we will follow these steps −answer := 0let x := Array in sorted formley y := Arrayfor i := 0 to size of ...

Read More

Find sum of a number and its maximum prime factor in C++

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

Suppose we have a positive number n, and we have to find the sum of N and its maximum prime factor. So when the number is 26, then maximum prime factor is 13, so sum will be 26 + 13 = 39.Approach is straight forward. Simply find the max prime factor, and calculate the sum and return.Example#include #include using namespace std; int maxPrimeFact(int n){    int num = n;    int maxPrime = -1;    while (n % 2 == 0) {       maxPrime = 2;       n /= 2;    }    for (int i = 3; i 2)    maxPrime = n;    return maxPrime; } int getRes(int n) {    int sum = maxPrimeFact(n) + n;    return sum; } int main() {    int n = 26;    cout

Read More

Maximize the median of an array in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 320 Views

Problem statementGiven an array arr[] of N elements and an integer K where K < N. The task is to insert K integer elements to the same array such that the median of the resultant array is maximizedIf input array is {1, 3, 2, 5} and k = 3 then−Sorted array becomes {1, 2, 3, 5}Insert 3 elements that are greater than 5. After this operation array becomes {1, 2, 3, 5, 6, 6, 6}Median of the new array is 5Algorithm1. In order to maximize the median of the resultant array, all the elements that need to be inserted must ...

Read More

Greatest Common Divisor of Strings in Python

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

Suppose there are two strings A and B. We can say that A is divisible by B, when A is created by concatenating B one or more times. So if A = “abcabc”, and B = “abc”, then A is divisible by B. In this section, we will see what is the greatest common divisor of a String. So return the largest string that divides both of the strings. So if two strings are “ABABAB”, and “ABAB”, then GCD will be “AB”To solve this, we will follow these steps −temp := shorter string between A and Bm := length of ...

Read More

Maximize the median of the given array after adding K elements to the same array in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 408 Views

Problem statementGiven an array arr[] of N elements and an integer K where K < N. The task is to insert K integer elements to the same array such that the median of the resultant array is maximizedIf input array is {1, 3, 2, 5} and k = 3 then −Sorted array becomes {1, 2, 3, 5}Insert 3 elements that are greater than 5. After this operation array becomes {1, 2, 3, 5, 6, 6, 6}Median of the new array is 5Algorithm1. In order to maximize the median of the resultant array, all the elements that need to be inserted ...

Read More

Maximum modulo of all the pairs of array where arr[i] >= arr[j] in C++

Narendra Kumar
Narendra Kumar
Updated on 11-Mar-2026 716 Views

In this problem, we are given an array, are of n elements. Our task is to create a program to find the maximum modulo of all pairs of array where arr[i] >= arr[j].Here, we have to find the maximum value of arr[i] % arr[j] where arr[i] >= arr[j].Let’s take an example to understand the problem, Input − arr[] = {3, 5, 9}Output − 4Explanation −All possible Pairs arr[i] and arr[j], 5, 3 => 5%3 = 2 9, 3 => 9%3 = 0 9, 5 => 9%5 = 4To solve this problem, a simple and direct approach will be run two ...

Read More

Find the center of the circle using endpoints of diameter in C++

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

Suppose we have two endpoints of diameter of a circle. These are (x1, y1) and (x2, y2), we have to find the center of the circle. So if two points are (-9, 3) and (5, -7), then the center is at location (-2, -2).We know that the mid points of two points are −$$(x_{m},y_{m})=\left(\frac{(x_{1}+x_{2})}{2},\frac{(y_{1}+y_{2})}{2}\right)$$Example#include using namespace std; class point{    public:       float x, y;       point(float x, float y){          this->x = x;          this->y = y;       }       void display(){          cout

Read More

Display Inline Working with CSS

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 131 Views

The CSS Display property with value inline renders an element according to content’s width, it does not force a line break. An element with display as inline renders as a element.SyntaxFollowing is the syntax for CSS display inline −Selector {    display: inline; }ExampleLet’s see an example of CSS display inline − CSS Display Inline form {    width:70%;    margin: 0 auto;    text-align: center; } * {    padding: 2px;    margin:5px;    box-sizing: border-box; } input[type="button"] {    border-radius: 10px; } .child{    height: 40px;    color: white;    border: 4px solid black; ...

Read More
Showing 28361–28370 of 61,297 articles
Advertisements