Programming Articles

Page 347 of 2544

Book Pagination in Python

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

Suppose we have a list of strings called book, if we page an index (0-indexed) into the book, and page_size, we have to find the list of words on that page. If the page is out of index then simply return an empty list.So, if the input is like book = ["hello", "world", "programming", "language", "python", "c++", "java"] page = 1 page_size = 3, then the output will be ['language', 'python', 'c++']To solve this, we will follow these steps −l:= page*page_sizereturn elements of book from index l to l+page_size - 1Let us see the following implementation to get better understanding ...

Read More

Program to find first N Iccanobif Numbers in C++

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

In this tutorial, we will be discussing a program to find N lccanobif numbers.For this we will be provided with an integer. Our task is to find the lccanobif number at that position. They are similar to the fibonacci number except the fact that we add the previous two numbers after reversing their digits.Example#include using namespace std; //reversing the digits of a number int reverse_digits(int num){    int rev_num = 0;    while (num > 0) {       rev_num = rev_num * 10 + num % 10;       num = num / 10;    } ...

Read More

How to find the total number of rows per group combination in an R data frame?

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

An R data frame that contains two or more factor columns then there are a greater number of combinations for the number of factors, obviously, if the number of factors is large with large number of levels then the combination of levels of the factors is also large. To find total number of rows per group combination we can use transform function.ExampleConsider the below data frame −set.seed(101) Group

Read More

Boss Fight in Python

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

Suppose we have a binary list called fighters and another list of binary lists called bosses. In fighters list the 1 is representing a fighter. Similarly, in bosses list 1 representing a boss. That fighters can beat a boss’s row if it contains more fighters than bosses. We have to return a new bosses matrix with defeated boss rows removed.So, if the input is like fighters = [0,1,1]011000001011111then the output will be011111To solve this, we will follow these steps −fighter_cnt := sum of all elements of fightersresult := a new listfor each row in bosses, doif fighter_cnt

Read More

Program to find GCD of floating point numbers in C++

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

In this tutorial, we will be discussing a program to find GCD of floating point numbers.For this we will be provided with two integers. Our task is to find the GCD (Greatest common divisor) of those two provided integers.Example#include using namespace std; //returning GCD of given numbers double gcd(double a, double b){    if (a < b)       return gcd(b, a);    if (fabs(b) < 0.001)       return a;    else       return (gcd(b, a - floor(a / b) * b)); } int main(){    double a = 1.20, b = 22.5;    cout

Read More

Find same contacts in a list of contacts in Python

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

Suppose we have a list of contacts holding username, email and phone number in any order, we have to find the same contacts (When same person have many different contacts) and return the same contacts together. We have to keep in mind that −A contact can store username, email and phone fields according to any order.Two contacts are same if they have either same username or same email or same phone number.So, if the input is like Contacts = [{"Amal", "amal@gmail.com", "+915264"}, { "Bimal", "bimal321@yahoo.com", "+1234567"}, { "Amal123", "+1234567", "amal_new@gmail.com"}, { "AmalAnother", "+962547", "amal_new@gmail.com"}], then the output will be [0, ...

Read More

How to X-axis labels to the top of the plot using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

Usually, a plot created in R or any of the statistical analysis software have X-axis labels on the bottom side but we might be interested in showing them at the top of the plot. It can be done for any type of two-dimensional plot whether it is a scatterplot, bar plot, etc. This is possible by using scale_x_continuous function of ggplot2 package in R.Exampleset.seed(123) x

Read More

Buying Cars in Python

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

Suppose we have a list of prices of cars for sale, and we also have a budget k, we have to find the maximum number of cars we can buy.So, if the input is like [80, 20, 10, 30, 80], k = 85, then the output will be 3 as we can buy three cars with prices 20, 10, 40To solve this, we will follow these steps −count := 0sort the list pricesfor i in range 0 to size of prices, doif prices[i]

Read More

Program to find GCD or HCF of two numbers using Middle School Procedure in C++

Ayush Gupta
Ayush Gupta
Updated on 11-Mar-2026 1K+ Views

In this tutorial, we will be discussing a program to find GCD or HCF of two numbers using Middle School Procedure.For this we will be provided with two numbers. Our task is to find the GCD (greatest common divisor) or HCF (highest common factor) for the given values.Example#include #define MAXFACTORS 1024 using namespace std; //structure to store factorization typedef struct{    int size;    int factor[MAXFACTORS + 1];    int exponent[MAXFACTORS + 1]; } FACTORIZATION; void FindFactorization(int x, FACTORIZATION* factorization){    int i, j = 1;    int n = x, c = 0;    int k = 1; ...

Read More

Maximize the number of sum pairs which are divisible by K in C++

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

Given the task is to calculate the maximum number of pairs arr[i] + arr[j] that are divisible by K where arr[] is an array containing N integers.Given the condition that a particular index number cannot be used in more than one pair.Inputarr[]={1, 2 ,5 ,8 ,3 }, K=2Output 2Explanation − The desired pairs are: (0, 2), (1, 3) as 1+5=6 and 2+8=10 . Both 6 and 10 are divisible by 2.Alternative answers could be the pairs: (0, 4), (1, 3) or (2, 4), (1, 3) but the answer remains the same, that is, 2.Input arr[]={1 ,3 ,5 ,2 ,3 ,4 }, K=3Output 3Approach ...

Read More
Showing 3461–3470 of 25,433 articles
« Prev 1 345 346 347 348 349 2544 Next »
Advertisements