Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by AYUSH MISHRA
Page 2 of 12
Maximum Subarray Sum - Kadane Algorithm using C#
In this problem, we are given an array of integers that may contain both positive and negative integers. We have to calculate the maximum sum of any contiguous subarray of the given array. In this article, we are going to learn how we can find the maximum subarray sum using the Kadane Algorithm using C#. Here is an example to find maximum sum in subarray: Example Input: arr = [1, -2, 3, 4, -1, 2, 1, -5, 4] Maximum Sum Subarray: [3, 4, -1, 2, 1] Sum = 3 + 4 + (-1) + 2 + 1 = 9 ...
Read MoreJavaScript program to remove vowels from a string
A string is a sequence of characters that can include alphabets, numbers, and symbols together or separately. In this article, we are going to learn how we can remove vowels from a given string in JavaScript using different approaches. There are a total of five vowels in the English alphabet. The five vowels in the English alphabet are: a, e, i, o, u, and they can be both uppercase or lowercase. Vowels are some specific alphabetic characters that represent specific speech sounds.There are a total of 5 vowels in 26 letters of the alphabet from A to Z, both ...
Read MoreC Program to Find if there is any subarray with a sum equal to 0
What is a Subarray? A subarray is a contiguous part of the array. The sum of elements in a subarray is the cumulative sum of elements of a subarray. For example: in the given array [1, 2, 3, 4, 5, 6] the subarray is [3, 4, 5]. In this article, we are given an array and need to find if any subarray has a sum equal to zero using C. Example 1 Input: arr[] = {4, 2, -3, 1} Output: Yes Explanation: The subarray {2, -3, 1} has a sum equal to 0. Example 2 ...
Read MoreProgram to Rotate a matrix by 90 degrees in the clockwise direction in C
In this article, we are given an N x N matrix, and our task is to rotate it by 90 degrees clockwise in C. Example Input: [1 2 3], [4 5 6], [7 8 9] Output: [7 4 1], [8 5 2], [9 6 3] Below are different approaches to rotate a matrix by 90 degrees in the clockwise direction: Using Brute Force Approach Using In-Place Rotation Using Brute Force Approach This is the simple and direct approach to understand and implement. In this approach, we create a ...
Read MoreCheck if all the 1s in a binary string are equidistant or not in C++
In this problem, we are given a binary string, and we have to check if all the 1s present in the binary string are at an equivalent distance from each other. Example 1 Input: binaryString = "10101010" Output: Yes Explanation The positions of 1s in the given string are 1, 3, 5, and 7.Here, the difference between consecutive 1s is 2 (as 7-5 equals 5-3 equals 3-1), so all 1s are at an equivalent distance from each other. Example 2 Input: binaryString = ...
Read MoreC++ program for finding nth term of H.P.
What is Harmonic Progression? A Harmonic Progression is a sequence of numbers formed by the reciprocal of an Arithmetic progression sequence. If a given sequence a1, a2, a3, a4... is in Arithmetic progression, then 1/a1, 1/a2, 1/a3, 1/a4... forms a Harmonic Progression. Formula for the nth term of Harmonic Progression? The formula for the nth term of a Harmonic Progression is: Tn = 1 / (1/a1 + (n - 1) * d) where: a1 is the first term of the Harmonic Progression. d is the common difference of the corresponding Arithmetic ...
Read MorePHP Program to Calculate the Average of an Array of Numbers
The average or mean of an array is a basic mathematical operation in programming. The average is used in analytics, finance, and reporting. One of the real-life applications is a website that calculates the average rating of a product or the average score of a test. In this article, we are going to learn how we can calculate the average of an array of numbers in PHP using different approaches. What is Average? The average is obtained by calculating the sum of all elements in an array and then dividing the sum by the total number of elements ...
Read MorePython Program to Rearrange an array such that arr[i] = i
In this problem, we are given an array and we have to rearrange the elements of the array such that for each index i, arr[i] = i. We have to rearrange the elements so that each element is in the position corresponding to its value. Scenario 1 Input: [3, 0, 2, 1] Output: [0, 1, 2, 3] Element 3 is the largest, so it is moved to the last index, 0 is the smallest element, so itismoved to the first index, 2 is moved to the third index, and 1 is moved to the second index. Scenario 2 ...
Read MoreMinimum sum of differences with an element in an array
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 MoreCheck if two numbers are coprime using Python
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