The arithmetic mean deviation or mean absolute deviation is the summation of the absolute differences of each element and the mean of the dataset, then dividing it by the total number of data elements. To calculate the minimum arithmetic mean deviation, we used the median of the dataset in place of the mean. The formula to calculate the minimum arithmetic mean deviation is given as: $$ \text{MMD} = \frac{1}{n} \sum_{i=1}^{n} |x_i - M| = \frac{|x_1 - M| + |x_2 - M| + \cdots + |x_n - M|}{n} $$ Here are some example scenarios to calculate the ... Read More
We are given the root of a binary tree and two integers, val and depth. The root of the binary tree is at depth 1. Our task is to add a new row of nodes with value val at the given depth. If the depth is 1, we have to create a new root node with value val and make the original tree its left child. If the depth is greater than 1, we go to all nodes at depth depth - 1, add new left and right child nodes with value val, and connect the original left and right ... Read More
Check if any Anagram of a String is Palindrome An anagram is a rearrangement of the characters of a word or a phrase to generate a new word, using all the original characters exactly once. For example, thing and night are anagrams of each other. While palindrome is a word or phrase that reads the same forward and backward, like madam, racecar. In this article, we are going to check if any anagram of a string is a palindrome or not, i.e., we are not just checking whether the given string itself is a palindrome, but also whether it can ... Read More
The Binary Search Tree (BST) is a widely used data structure that maintains the elements in a sorted hierarchical order. Each node in the BST follows the specific property: The values in the left subtree are always less than the values of the current node. The values in the right subtree are always greater than the node. In this article, we are going to learn about checking if an array represents the inorder of a BST or not in Python. Checking for inorder of the BST Inorder traversal is the ... Read More
Check if Array Can Be Divided into Pairs with Sum Divisible by K In this article, we are given an array of integers and a number k. The task is to determine whether it is possible to divide the entire array into pairs such that the sum of every pair is divisible by k. For example, if the given array of integers is [2, 4, 1, 3], and a value k = 5. The task is to form pairs (two elements at a time) from the array such that when you add each pair, the result is divisible by ... Read More
Matrices are used to represent and manipulate structured data (such as grids, patterns). While working with matrix manipulation, we may find scenarios where to determine whether all the rows in a given matrix are circular rotations of one another. Circular Rotation in a Matrix A circular rotation of a list (or array) is a transformation where elements are shifted to the left (or right), and the element at the end will be wrapped around to the beginning. For example, if the original row is [1, 2, 3], its circular rotations are: [2, 3, 1] (left-rotated ... Read More
In this article, we will learn how to find a path between two nodes in an undirected graph and implement it in C++. We will represent graph as an adjacency list and use a depth-first search (DFS) algorithm to find the path. We already discussed finding a path between two nodes in a directed graph, check here. Finding Path Between Two Nodes in an Undirected Graph We have an adjacency list representation of an undirected graph adj[] and two nodes src and dest, our task is to write a program that finds the path between the src ... Read More
An array is a group of similar elements stored together in a single variable which take contiguous memory locations. Arrays help us to store and manage multiple values of the same type, like a list of numbers or names.In this article, we will solve a beginner level problem in C++ that involves decreasing all the even numbers in an array by 1. Program to Decrease Even Numbers in an Array How to Check a if Number is Even in C++? C++ Program to Decrease Even Numbers ... Read More
A directed graph is a graph where the edges specify a direction from one vertex to another. In this article, we will learn how to find a path between two vertices in a directed graph and implement C++ code to achieve this. To determine if there is a path between two vertices, there are two common algorithms we can use: BFS Algorithm to Find Path Between Two Vertices DFS Algorithm to Find Path Between Two Vertices First of all, let's understand what does it meant by having a ... Read More
In this article, we are given a larger number and we need to check whether it is divisible by 11 or not using the C++ program. To handle large numbers, we treat the number as a string and apply a divisibility rule to check if it's divisible by 11. Rule of Divisibility by 11 A number is divisible by 11 if the difference between the sum of its digits at odd positions and the sum of its digits at even positions is divisible by 11. Consider the following example scenarios to understand the divisibility of a large number ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP