Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 10 of 17

Cumulative sum at each index in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 982 Views

In JavaScript, calculating the cumulative sum (also known as running sum or prefix sum) at each index means computing the sum of all elements from the beginning of the array up to the current position. This is a common array operation used in algorithms and data analysis. What is Cumulative Sum? The cumulative sum is the calculation of the sum of a series of numbers up to a given index. Each element in the resulting array represents the sum of all previous elements including the current element. For example, given an array [1, 2, 3, 4, 5], ...

Read More

Numbers smaller than the current number JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 632 Views

In JavaScript, we often need to count how many numbers in an array are smaller than each element. This problem requires comparing each element against all others to build a result array showing the count of smaller numbers for each position. Understanding the Problem Given an array of integers, we need to return a new array of the same length where each element represents the count of numbers smaller than the corresponding element in the original array. For example: if we have [5, 4, 3, 2, 1], the output should be [4, 3, 2, 1, 0] because: ...

Read More

Finding all duplicate numbers in an array with multiple duplicates in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 865 Views

In JavaScript, finding duplicate numbers in an array is a common task that can be efficiently solved using objects to track element frequencies. This approach helps identify all numbers that appear more than once in the array. Understanding the Problem We need to find all duplicate numbers in an array that may contain multiple duplicates. For example, given the array [1, 1, 4, 8, 2, 2, 6, 6, 6], the duplicate numbers are [1, 2, 6] since these appear more than once. Using Object to Count Frequencies The most efficient approach uses an object to count ...

Read More

Fetch Numbers with Even Number of Digits JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 511 Views

In JavaScript, finding numbers with an even count of digits means identifying numbers where the total digit count is divisible by 2. This is different from finding even numbers themselves. Understanding the Problem We need to create a function that takes an array of numbers and returns only those numbers that have an even number of digits. For example, in the array [12, 345, 67, 8910, 11, 9], the numbers 12 (2 digits), 67 (2 digits), and 8910 (4 digits) have even digit counts. Method 1: Using String Length Convert each number to a string and ...

Read More

Pick out numbers from a string in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 261 Views

In JavaScript, extracting numbers from strings is a common task that can be efficiently accomplished using regular expressions and built-in string methods. This approach allows you to find and extract numeric values from mixed content. Understanding the Problem The goal is to extract all numeric values from a given string. For example, from the string "I am 25 years old and earn $1500.50", we want to extract [25, 1500.50]. This involves pattern matching to identify numeric sequences including integers and decimal numbers. Using Regular Expressions with match() ...

Read More

Maximum difference between a number JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 417 Views

In this problem statement, our task is to write a function for finding the maximum difference between two numbers in an array using JavaScript. We'll explore both a brute force approach and an optimized solution. Understanding the Problem We need to find the maximum difference between any two numbers in an array where the larger number appears after the smaller number in the array order. For example, in array [2, 3, 5, 6, 4, 1], the maximum difference is 4 (6 - 2 = 4), not 5 (6 - 1), because 1 comes after 6. Method 1: ...

Read More

Check whether we can form string2 by deleting some characters from string1 without reordering the characters of any string - JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 316 Views

In this problem, we need to determine whether we can form string2 by removing some characters from string1 without changing the order of characters in either string. This is essentially checking if string2 is a subsequence of string1. Understanding the Problem We want to check if the second string can be formed from the first string while preserving character order. Let's look at some examples: // Example 1: Can form "ale" from "apple" let s1 = "apple"; let s2 = "ale"; console.log("Can form '" + s2 + "' from '" + s1 + "'?"); // Expected: ...

Read More

Return the element that appears for second most number of times in the array JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 430 Views

In JavaScript, finding the element that appears for the second most number of times in an array requires counting frequencies and identifying the second highest count. We'll use a frequency map and sorting to solve this problem efficiently. Understanding the Problem Given an array of elements, we need to find the element with the second highest frequency. For example, in the array [1, 3, 3, 4, 4, 4], the element 4 appears 3 times (most frequent), and 3 appears 2 times (second most frequent), so we return 3. Algorithm Steps Step 1: Create a frequency map ...

Read More

Find the greatest product of three numbers in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 641 Views

In JavaScript, finding the greatest product of three numbers from an array requires considering both positive and negative numbers. This problem has multiple approaches, from brute force to optimized sorting methods. Understanding the Problem Given an array of integers, we need to find three numbers whose product is the largest among all possible combinations. For example, with array [1, 5, 3, 2, 4], the three largest numbers (3, 4, 5) give us the product 3 × 4 × 5 = 60. ...

Read More

Mapping values to keys JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 819 Views

In JavaScript, mapping values to keys means creating associations between identifiers (keys) and their corresponding data (values). This is commonly achieved using objects, which store data in key-value pairs for efficient retrieval. Understanding the Problem Objects in JavaScript are data structures that store information as key-value pairs. Keys serve as identifiers to access their associated values. There are several ways to access these values, with dot notation and bracket notation being the most common approaches. For example, with an object const obj = {name: 'John', age: 30}, you can access the name using obj.name or obj['name']. ...

Read More
Showing 91–100 of 163 articles
« Prev 1 8 9 10 11 12 17 Next »
Advertisements