AYUSH MISHRA

AYUSH MISHRA

112 Articles Published

Articles by AYUSH MISHRA

Page 4 of 12

Minimum sum of differences with an element in an array

AYUSH MISHRA
AYUSH MISHRA
Updated on 27-Mar-2025 2K+ Views

Problem Statement In this problem, we are given an array of integers, and we have to select a particular element from the array such that the sum of absolute differences between that element and all other elements is minimized. Example 1 Input: arr = [3, 1, 2, 5, 4] Output: 6 Explanation: If we select 3 as the element, the sum of differences is: |3-1| + |3-2| + |3-3| + |3-4| + |3-5|= 2 + 1 + 0 + 1 + 2 = 6 ...

Read More

Check if two numbers are coprime using Python

AYUSH MISHRA
AYUSH MISHRA
Updated on 27-Mar-2025 862 Views

In this article, we are going to learn how we can check whether two given numbers are co-prime in Python using different approaches. What are Co-prime Numbers? Two numbers are said to be co-prime numbers if they have no common factors other than 1. Checking if two numbers are co-prime We can check if two given numbers are co-prime numbers by finding their GCD (Greatest Common Factor). GCD is also known as HCF (Highest Common Factor). If the GCD of two numbers is 1, then those numbers are co-prime numbers; otherwise, they are not co-prime numbers. Below are the examples ...

Read More

C++ Program to count the number of days in a given month of a year

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 27-Mar-2025 2K+ Views

There are a total of 365 days in a normal year and 366 days in a leap year. In this article, we are going to learn how we can find the number of days in a month of a given particular year. Here, we will learn about different approaches for calculating the number of days in a given month using C++. How to Find the Number of Days in a Given Month? There are a total of 12 months in a year. The number of days in a given month from 1 to 12 in a given leap or non-leap ...

Read More

JavaScript program to find Number of Squares in an N*N grid

AYUSH MISHRA
AYUSH MISHRA
Updated on 26-Mar-2025 3K+ Views

A grid is a 2-dimensional arrangement of squares divided into rows and columns. From a given N*N square grid we have to calculate the total number of squares possible. There are multiple ways to find the number of squares in a given grid. In this article, we are going to learn about various approaches for calculating the number of squares in a given grid of size N*N. Direct Formula for Finding the Number of Squares in an N*N Grid The direct formula for finding the total number of squares in an N * N grid is Total Number of ...

Read More

Sorting strings with decimal points in C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 21-Mar-2025 2K+ Views

A string containing decimal points is sorted to solve complex programming problems. This question was asked in the Accenture coding assessment in 2025. In C++, there are different ways to sort such strings efficiently. In this article, we are going to discuss various approaches to sorting strings that contain decimal points using C++. How to Sort Strings with Decimal Points? In this problem, we are given an array of strings, where each string represents a decimal number. The goal is to sort these strings in increasing numerical order while ensuring the correct handling of decimal values. Example 1 ...

Read More

Sorting an array of binary values - C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 21-Mar-2025 461 Views

Sorting an array of binary values (0s and 1s) is a common problem in programming. In C++, there are multiple ways to efficiently sort an array containing only 0s and 1s. In this article, we are going to learn various approaches to sorting an array of binary values using C++. How to Sort an Array of Binary Values? In this problem, we are given an array that consists of only 0s and 1s. The task is to sort the array in ascending order, which means all 0s should come before all 1s. Example 1 ...

Read More

Python Program for finding nth term of H.P.

AYUSH MISHRA
AYUSH MISHRA
Updated on 20-Mar-2025 1K+ Views

A Harmonic Progression ( H.P.) is a sequence of numbers where the reciprocals of the terms form an Arithmetic Progression (A.P.). In simple terms, if we take the reciprocal of each term in an H.P., the resulting sequence will be in A.P. In this problem, we are given the first term, common difference, and value of n of which we have to find the nth term of given H.P. Find the nth term of H.P. To find the nth term of Harmonic Progression, we first convert the H.P. into an A.P. by finding reciprocals of the terms. The formula ...

Read More

Find the number that appears once, and the other numbers twice in Python

AYUSH MISHRA
AYUSH MISHRA
Updated on 20-Mar-2025 2K+ Views

Finding a unique number in a list that appears only once while all other numbers appear twice is a common and important problem in programming. We can find the unique number in a list using multiple ways. The most efficient approach is using an XOR operator, as this method solves this problem in constant time and space complexity. In this article, we are going to discuss various approaches to finding the number that appears once while all others appear twice. Finding the Unique Number When we are given a list of numbers where every number appears twice except one ...

Read More

First and last position of an element in a sorted array in C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 20-Mar-2025 4K+ Views

The first and last position of any element in a sorted array is a common operation in the world of programming. In C++, there are multiple ways to find the first and last position of an element in a sorted array. In this article, we are going to discuss various approaches for finding the first and last occurrence of an element in a sorted array using C++. How to Find the First and Last Position of an Element? In this problem, we are given a sorted array and a target element. We need to find the first and last ...

Read More

C# program to find first set bit

AYUSH MISHRA
AYUSH MISHRA
Updated on 20-Mar-2025 4K+ Views

In this problem, we are given a number n, and we need to find the position of the first set bit (1-bit) in its binary representation. In this article, we are going to discuss different approaches to solving this problem using C#. Example 1 Input: N = 18 Output: 2 Explanation: The binary representation of 18 is 10010. The first set bit from the right is at position 2. Example 2 Input: N = 12 Output: 3 Explanation: The binary ...

Read More
Showing 31–40 of 112 articles
« Prev 1 2 3 4 5 6 12 Next »
Advertisements