Programming Articles

Page 362 of 2544

Find element position in given monotonic sequence in Python

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

Suppose we have a number l and a monotonic increasing sequence f(m), where f(m) = am + bm [log2(m)] + cm^3 and (a = 1, 2, 3, …), (b = 1, 2, 3, …), (c = 0, 1, 2, 3, …)Here [log2(m)] is the log to the base 2 and round the value down. so, if m = 1, the value is 0.if m = 2-3, the value is 1.if m = 4-7, the value is 2.if m = 8-15, the value is 3. and so, onwe have to find the value m such that f(m) = l, if l ...

Read More

Count of index pairs with equal elements in an array in C++

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

We are given with an array of N elements. The goal is to find the index pairs (i, j) which have the same element value such that i!=j. i.e, Arr[i]=Arr[j] and i!=j. This is used to make pairs of gloves of equal size. Out of N gloves only paired gloves are useful to sell.We will do this by running two loops with 0 -1. Total pairs=2Approach used in the below program is as followsWe take an integer array Arr[] initialized with random numbers for size of gloves > 0.Take a variable n which stores the length of Arr[].Function countPairs(int arr[], ...

Read More

How to change the angle of annotated text in plot created by using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 323 Views

To annotate the text inside a plot created by ggplot2, we can use annotate function. It is used to give some explanation about the plot or add any useful information that will help readers to understand the plot in a better way. Sometimes, we might want to change the angle of the annotated text, especially in cases where we have some information that is presented vertically in the plot, therefore, we can use angle argument of the annotate function.ExampleConsider the below data frame −> x y df dfOutput      x       y 1 4.086537 5.890591 2 2.271184 ...

Read More

Maximum sum subsequence with at-least k distant elements in C++

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

In this tutorial, we will be discussing a program to find maximum sum subsequence with at-least k distant elements.For this we will be provided with an array containing integers and a value K. Our task is to find the subsequence having maximum sum such that all the elements are at least K elements apart.Example#include using namespace std; //finding maximum sum subsequence int maxSum(int arr[], int N, int k) {    int MS[N];    MS[N - 1] = arr[N - 1];    for (int i = N - 2; i >= 0; i--) {       if (i + ...

Read More

Unreachable statement using final variable in Java

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 255 Views

Unreachable statements are those that don’t get executed when the code is being executed. This could be so because −There is a return statement before the code.There is an infinite loop in the code.The execution of the code is terminated forcibly before it executes.Here, we will see how the unreachable statement can be used with the ‘final’ keyword −Exampleclass Demo_example{    final int a = 56, b = 99;    void func_sample(){       while (a < b){          System.out.println("The first value is less than the second.");       }       System.out.println("This is ...

Read More

Find First element in AP which is multiple of given Prime in Python

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

Suppose we have a first term (A) and common difference (d) of an AP series, and we also have a prime number P, we have to find the position of the first element in the given AP which is the a multiple of the given prime number P.So, if the input is like A = 3, D = 4, P = 5, then the output will be 3 as fourth term of the given AP is a multiple of the prime number 5. So, first term = 3, second term = 3+4 = 7, third term = 3+2*4 = 11 ...

Read More

Maximize number of continuous Automorphic numbers in C++

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

Given the task is to maximize the number of continuous Automorphic elements in a given array with N number of elements.An automorphic number is a number whose square ends with the same digits as the number itself. For example 5 is an automorphic number as 5*5 = 25 and 25 ends with 5.Let’s now understand what we have to do using an example −Input − arr[]={5, 3, 625, 6, 8, 1}Output − 2Explanation − Automorphic numbers present in the above array are 5, 625, 6 and 1 but the maximum continuous automorphic numbers are {625, 6} which makes the output ...

Read More

Counting numbers whose difference from reverse is a product of k in C++

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

We are given a range [l,r] and a number k. The goal is to find all the numbers between l and r (l

Read More

How to find the cumulative sums if a vector contains NA values in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 919 Views

The cumulative sums are the sum of consecutive values and we can take this sum for any numerical vector or a column of an R data frame. But if there exits an NA, then we need to skip it and therefore the size of the cumulative sums will be reduced by the number of NA values. If we have NA values in a vector then we can ignore them while calculating the cumulative sums with cumsum function by using !is.na.Examples> x1 x1Output[1] 1 2 3 4 5 6 7 8 9 10 NA > cumsum(x1[!is.na(x1)]) [1] 1 3 6 10 ...

Read More

Sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n in C++

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

In this problem, we are given a number n which defines the n-th term of the series 2^0, 2^1, 2^2, …, 2^n. Our task is to create a program to find the sum of the series 2^0 + 2^1 + 2^2 +...+ 2^n.Let’s take an example to understand the problem, Inputn=6Output Explanation sum = 2^0 + 2^1 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 sum = 1 + 2 + 4 + 8 + 16 + 32 + 64 = 127A simple solution to the problem is by using the loop. Finding the 2^i, for each value from 0 ...

Read More
Showing 3611–3620 of 25,433 articles
« Prev 1 360 361 362 363 364 2544 Next »
Advertisements