Programming Articles

Page 1350 of 2547

Triples with Bitwise AND Equal To Zero in C++

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

Suppose we have an array of integers A. We have to find the number of triples of indices (i, j, k) such that −0

Read More

Subarrays with K Different Integers in C++

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

Suppose we have an array A of positive integers, we can call a good subarray (contiguous) of A, if the number of different integers in that subarray is exactly K. So, if the array is like [1, 2, 3, 1, 2] has 3 different integers: 1, 2, and 3. We have to find the number of good subarrays of A.So, if the input is like [1, 2, 3, 1, 4] and K = 3, then the output will be 4, as it can form three subarrays with exactly four distinct integers, these are [1, 2, 3], [1, 2, 3, 1], ...

Read More

Number of Squareful Arrays in C++

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

Suppose we have an array A of positive integers, we can say that array is squareful if for every pair of adjacent elements, their sum is a perfect square. We have to find the number of permutations of A that are squareful. Two permutations A1 and A2 will not be same if and only if there is some index i such that A1[i] not same as A2[i].So, if the input is like [3, 30, 6], then the output will be 2, as we have two permutations like [3, 6, 30], [30, 6, 3].To solve this, we will follow these steps ...

Read More

Java Lambda Expression with Collections

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 988 Views

Sorting the elements of a list using lambda expression −Exampleimport java.util.*; public class Demo{    public static void main(String[] args){       ArrayList my_arr = new ArrayList();       my_arr.add(190);       my_arr.add(267);       my_arr.add(12);       my_arr.add(0);       System.out.println("Before sorting, elements in the array list are : " + my_arr);       Collections.sort(my_arr, (o1, o2) -> (o1 > o2) ? -1 : (o1 < o2) ? 1 : 0);       System.out.println("After sorting, elements in the array list are : " + my_arr);    } }OutputBefore sorting, elements in ...

Read More

Minimum Cost to Merge Stones in C++

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

Suppose we have N piles of stones arranged in a row. Here the i-th pile has stones[i] number of stones. A move consists of merging K consecutive piles into one pile, now the cost of this move is equal to the total number of stones in these K number of piles. We have to find the minimum cost to merge all piles of stones into one pile. If there is no such solution then, return -1.So, if the input is like [3, 2, 4, 1] and K = 2, then the output will be 20, this is because, we will ...

Read More

Count common characters in two strings in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 2K+ Views

We are given with the two strings let’s say str1 and str2 and the task is to find the count of common characters in two strings i.e. if str1[i] = str[j], then they will be considered as a pair and count will increased to 1 and if str1[i]!=str2[j] then they willn’t be considered as a pair and count willn’t increase to 1.For ExampleInput − str1 = “hello”       str2 = “heoo” Output − count is: 3Explanation − str1[0] = str2[0] i.e. h ; str1[1] = str2[1] i.e. e ; str1[2]!=str2[2] i.e. l and o; str1[3]=str2[3] i.e. o. So, the ...

Read More

Java Numeric Promotion in Conditional Expression

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 218 Views

The conditional operator (? :) leverages the output of one value (which is a bool) to decide which expression has to be evaluated next. Let us see an example −Exampleimport java.io.*; public class Demo{    public static void main (String[] args){       Object my_obj = true ? new Integer(91) : new Float(89);       System.out.println(my_obj);    } }Output91.0A class named Demo contains the main function. Here, an object instance is defined and if it is true, an integer value is displayed otherwise a float value is displayed. Next, they are printed on the console.When promotional expression is ...

Read More

Count even and odd digits in an Integer in C++

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 3K+ Views

We are given with an integer number and the task is to count the even numbers and the odd numbers in a digit. Also, we will keep check on whether the even digits in an integer are occurring an even number of times and also the odd digits in an integer are occurring an odd number of times.For ExampleInput − digit = 12345 Output − count for even digits = 2       count for odd digits = 3Explanation − Yes, Also, even digits are occurring even number of times i.e. 2 and odd digits are occurring odd number ...

Read More

Numbers With Repeated Digits in C++

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

Suppose we have a positive integer N, we have to find the number of positive integers less than or equal to N that have at least 1 repeated digit .So, if the input is like 99, then the output will be 9, as we have numbers like 11, 22, 33, 44, 55, 66, 77, 88, 99.To solve this, we will follow these steps −Define a function A(), this will take m, n, ret := 1for initialize i := 0, when i < n, update (increase i by 1), do −ret := ret * m(decrease m by 1)return retFrom the main ...

Read More

Count factorial numbers in a given range in C++

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

We are given the range starting from an integer value holded by a variable let’s say start till the variable end and the task is to count the total number of factorial numbers available in the given range.What is a factorial numberFactorial of a number is calculated by multiplying the digits in a number while decrementing thevalue of digit by 1. It is denoted by the symbol ‘!’ i.e. 0!, 1!, 2!, 3!, 5!, ...., etc. Factorial of 0! and 1! is always 1.I.e. factorial of 2 = 2 * (2-1) = 2 * 1 = 2       ...

Read More
Showing 13491–13500 of 25,466 articles
Advertisements