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
-
Economics & Finance
Articles by AYUSH MISHRA
Page 3 of 12
Calculate the sum of squares of the first N natural numbers in C#
In this problem, we are given a number N, and we need to calculate the sum of the squares of the first N natural numbers. The first N natural numbers are 1, 2, 3, ..., N, and we need to find 1² + 2² + 3² + ... + N². Problem Description Given a positive integer N, calculate the sum of squares of the first N natural numbers using different approaches in C#. Example 1 Input: N = 4 Output: 30 Explanation: The squares of the first 4 natural numbers are: 1², ...
Read MoreConvert a number to Roman numerals in C#
Converting a number to Roman numerals in C# is a common programming problem that involves mapping integer values to their corresponding Roman numeral representations. Roman numerals use specific symbols like I, V, X, L, C, D, and M to represent numbers. Roman Numeral System Roman numerals follow specific rules where certain combinations represent subtraction (like IV for 4, IX for 9). The key is to use a mapping of values in descending order, including these special cases − Roman Numeral Values M = 1000 ...
Read MoreJavaScript program to find Number of Squares in an N*N grid
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. Understanding the Problem In an N×N grid, we can form squares of different sizes. For example, in a 4×4 grid, we can have: 1×1 squares: 16 ...
Read MoreHow to Filter Object by Keys in Lodash?
Sometimes while working with objects in JavaScript we want to filter objects based on keys. We can easily do this by using Lodash, a popular JavaScript library that provides several inbuilt functions to achieve this easily. In this article, we are going to discuss how we can Filter Objects by Keys using Lodash. Prerequisite Lodash: Lodash is a popular JavaScript library used to deal with a variety of functions such as arrays, objects, strings, and more. Install Lodash We can install the Lodash library in the project by adding it via CDN ...
Read MoreHow to Filter Object by Values in Lodash?
Sometimes we are given an object and we want to extract only the key-value pairs that meet certain criteria. In this article, we are going to discuss how we can filter objects by values in Lodash. Prerequisite Lodash: Lodash is a popular JavaScript library used to deal with a variety of functions such as arrays, objects, strings, and more. Install Lodash We can install the Lodash library in the project by adding it via CDN or npm using the following command: npm install lodash Approaches to Filter Object ...
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. The five vowels in the English alphabet are: a, e, i, o, u, and they can be both uppercase or lowercase. Problem Examples Example 1 Input: Anshu Ayush Output: nsh ysh Explanation The vowels in the string "Anshu Ayush" are A, u, A, u. After removing them, the remaining string is "nsh ysh". Example ...
Read MoreReplace elements by its rank in the array in JavaScript
In this problem, we are given an array, and we have to replace each element with its rank. The rank of an element is the position of the element when the array is arranged in sorted order with unique values only. In this article, we are going to learn about various approaches to replacing elements with their rank in an array using JavaScript. Below are the examples to understand the problem clearly: Example 1 Input: arr = [40, 10, 20, 30] Output: [4, 1, 2, 3] Explanation: The sorted, unique array is: [10, 20, ...
Read MoreCount the number of nodes in a complete Binary tree using JavaScript
A binary tree is a non-linear data structure where each node can have at most two children: left and right. In this article, we'll explore how to count nodes in a complete binary tree using JavaScript. What is a Complete Binary Tree? A complete binary tree is a binary tree where all levels are completely filled except possibly the last level, and the last level has all nodes filled from left to right. 1 ...
Read MoreJavaScript program to find the average of all negative numbers in an array
In this problem, we are given an array of integers, which may contain both negative and positive numbers. We have to find the average of all the negative numbers in the array. In this article, we are going to learn how we can find the average of all negative numbers in an array using JavaScript. Problem Examples Example 1 Input: arr = [1, -3, 4, -2, -5]; Output: -3.33 Explanation: The negative numbers in the array are -3, -2, and -5. Their sum is -10, and the number of negative elements is 3. The average is: ...
Read MoreHow to Get Last Day of Previous Month from Date in Moment.JS?
When working with dates in JavaScript, it's common to need specific dates for calculations or validations. One such situation is determining the last day of the previous month from a given date. In this article, we'll learn how to get the last day of the previous month using Moment.js. Prerequisite Moment.js: Moment.js is a popular JavaScript library used to parse, validate, manipulate, and display dates and times in JavaScript. You can install Moment.js in your project via npm: npm install moment Approaches to Get Last Day of Previous Month Below are two ...
Read More