Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 3 of 17

JavaScript: Adjacent Elements Product Algorithm

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

In this article, we will learn to calculate the adjacent elements product with the help of JavaScript functionalities. This problem is often asked in coding interviews or algorithm challenges, and it tests one's understanding of array manipulation and performance optimization. Problem Statement Given an array of integers, your task is to return the largest product that can be obtained by multiplying any two adjacent numbers in the array. For example − Input: [5, 1, 2, 3, 1] Output: 6 The adjacent elements are (5, 1), (1, 2), (2, 3), and (3, 1). The largest ...

Read More

Nth element of the Fibonacci series JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In this article, we'll learn how to find the nth element in the Fibonacci series using JavaScript. The Fibonacci sequence is a mathematical series where each number is the sum of the two preceding numbers. What is the Fibonacci Series? The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the previous two numbers. The series begins as: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89... For example, the 6th number in the series is 8, and the 10th number is 55. Using ...

Read More

Finding all the Longest Strings from an Array in JavaScript

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

In the given problem statement we have to find all the longest strings from an array with the help of JavaScript functionalities. This task can be done by getting the length of each string and then comparing these lengths with the maximum length. Understanding the Problem The problem is to find all the longest strings from an array in JavaScript. We have an array of strings and our task is to identify the strings with maximum length and return them as a new array. For example: if we have an array ['abc', 'defg', 'hijkl', 'mnopqr', 'stuvwxyz'], the longest ...

Read More

Algorithm to get the combinations of all items in array JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 4K+ Views

In this problem statement, our task is to get the combinations of all items in an array with the help of Javascript functionalities. We can use a recursive approach that iteratively adds items to a running list of combinations. Understanding the Problem The goal is to write a function in Javascript that finds all possible combinations of elements in an array. For example, if we have an array [1, 2, 3], the combinations would be: [ [], [1], [2], [3], [1, 2], [1, ...

Read More

Finding the largest prime factor of a number in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In JavaScript, finding the largest prime factor of a number involves dividing the number by its prime factors until we reach the highest one. This is commonly solved using prime factorization. Understanding Prime Factors A prime factor is a prime number that divides the given number exactly (without remainder). For example, the number 84 has prime factors: 2, 2, 3, and 7. Among these, 7 is the largest prime factor. Algorithm Approach We use prime factorization by starting with ...

Read More

Random whole number between two integers JavaScript

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

In JavaScript, generating a random whole number between two integers is a common task that requires combining Math.random() with Math.floor() to ensure we get integers within the specified range. Understanding the Problem We need to create a function that returns a random integer between two given numbers (inclusive). For example, if we want a random number between 1 and 5, the possible outputs are: 1, 2, 3, 4, or 5. The Math.random() Method Math.random() generates a random decimal number between 0 (inclusive) and 1 (exclusive). We need to transform this to get integers in our desired ...

Read More

Find the largest palindrome number made from the product of two n digit numbers in JavaScript

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

In this problem, we need to find the largest palindrome number that can be created by multiplying two n-digit numbers using JavaScript. We'll implement two functions: one to find the largest palindrome product and another to check if a number is palindromic. What are Palindrome Numbers? A palindrome number reads the same forwards and backwards. Examples include 44, 121, 202, 404, and 909. When reversed, these numbers remain identical to their original form. Understanding the Problem We need to find the largest possible palindrome that results from multiplying two n-digit numbers. For example, with 2-digit numbers ...

Read More

Sorting odd and even elements separately JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 1K+ Views

In JavaScript, we can sort odd and even positioned elements separately within an array while maintaining their relative positions. This approach sorts elements at even indices (0, 2, 4...) and odd indices (1, 3, 5...) independently. Understanding the Problem Given an array, we need to sort elements at even indices separately from elements at odd indices. For example, with array [9, 2, 7, 4, 5, 6, 3, 8, 1]: Even indices (0, 2, 4, 6, 8): [9, 7, 5, 3, 1] → sorted: [1, 3, 5, 7, 9] Odd indices (1, 3, 5, 7): [2, 4, ...

Read More

Smallest number that is divisible by first n numbers in JavaScript

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

In this problem, we need to find the smallest number that is divisible by all numbers from 1 to n. This is essentially finding the Least Common Multiple (LCM) of the first n natural numbers. Understanding the Problem The problem requires finding the smallest positive integer that is evenly divisible by each of the numbers from 1 to n without any remainder. For example, if n = 4, we need the smallest number divisible by 1, 2, 3, and 4, which is 12. Logic and Approach We solve this using the Least Common Multiple (LCM) concept. ...

Read More

Adding a unique id for each entry in JSON object in JavaScript

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 5K+ Views

In this problem statement, our task is to add a unique id for every object entry in a JSON object with the help of JavaScript. We will use a loop and a variable to store the id for each object in the JSON object. Understanding the Problem Statement The problem statement is to write a function in JavaScript that adds a unique id to every item in the given JSON object. For example, if we have: let obj = { "entry1": {empName: "A", age: 25}, "entry2": {empName: "B", age: 30} ...

Read More
Showing 21–30 of 163 articles
« Prev 1 2 3 4 5 17 Next »
Advertisements