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 Nikitasha Shrivastava
Page 5 of 17
All possible odd length subarrays JavaScript
In this problem statement, our task is to find all the possible odd length subarrays with the help of JavaScript functionalities. This task can be done with the help of some built-in functions of JavaScript or we can solve it by multiple for loops. Logic for the Given Problem The problem states that we have to get all the possible odd length subarrays in JavaScript programming language. The meaning of odd length is that the length of the subarrays should be 1, 3, 5, 7, and so on. So our task is to filter the subarrays with odd ...
Read MoreDynamic Programming - Part sum of elements JavaScript
In this problem, we calculate the sum of all elements except one element at each step, creating an array of partial sums. We'll implement this using JavaScript array methods and dynamic programming concepts. Problem Statement Given an array of n elements, generate an array containing: The sum of all elements The sum of all elements except the first element The sum of all elements except the second element And so on for each element Algorithm Step 1: Calculate the total sum of all elements in the array. Step 2: Create a result array starting ...
Read MoreGiven an array of integers, find the pair of adjacent elements that has the largest product and return that product JavaScript
Finding the pair of adjacent elements with the largest product is a common array problem in JavaScript. This involves iterating through the array and comparing products of consecutive elements. Problem Understanding Given an array of integers, we need to find two adjacent elements whose product is maximum among all possible adjacent pairs. For example, in array [1, 2, 3, 4], the adjacent pairs are (1, 2), (2, 3), and (3, 4) with products 2, 6, and 12 respectively. Method 1: Using -Infinity for Initialization This approach initializes the maximum product with -Infinity to handle arrays with ...
Read MoreChecking if a number is some power of the other JavaScript
In this problem statement, our objective is to check if a given input number is some power of another number using JavaScript functionalities. Logic for the Problem To determine if a number a is a power of another number b, we can use logarithms. If a = b^n for some integer n, then log_b(a) = n should be an integer. Since JavaScript's Math.log() returns the natural logarithm, we use the change of base formula: log_b(a) = ln(a) / ln(b). If this result is an integer, then a is a power of b. Algorithm Step 1 ...
Read MoreN consecutive odd numbers JavaScript
In this problem statement, our target is to print the n consecutive odd numbers and implement this problem with the help of Javascript functionalities. We can solve this problem using loops and array manipulation in JavaScript. Logic for the Given Problem In the given problem statement we have to design a program to generate a given number of consecutive odd numbers starting from 1. It will be done by creating an empty array to store the odd numbers and then using a loop which will run n times to add every odd number to the created array. ...
Read MoreJavaScript Count repeating letter
In this problem statement, our target is to count the repeating letter in the given string with the help of Javascript functionalities. So we can solve this problem with the help of loops and some built-in methods of Javascript. Logic for the given problem In the given problem statement we have to design a program to count the repeating letters in the given string. For implementing this task first we will create a blank object for count, array for repeated characters and another object for results. Then we will loop through every character in the string. So ...
Read MoreSorting numbers according to the digit root JavaScript
In this problem statement, our task is to sort numbers according to the digit root and implement this problem with the help of Javascript functionalities. So we can solve this problem with the help of loops in Javascript. What is digit root? The digit root of a given number is basically the sum of its digits. Repeat the calculation until the result is not a single digit. Let's take an example for the digit root, calculate the digit root for 1234, 1 + 2 + 3 + 4 = 10 = 1 + 0 = 1. Similarly the ...
Read MoreFunction to reverse a string JavaScript
In JavaScript, reversing a string is a common programming task that can be accomplished using various approaches. This tutorial demonstrates how to create a function that reverses any given string by iterating through its characters in reverse order. Understanding the Problem String reversal means rearranging the characters of a string so that the last character becomes first, second-last becomes second, and so on. For example, if we have the string "Hello", the reverse will be "olleH". Algorithm Step 1 − Declare a variable to store the reversed string and initialize it as empty. Step 2 − ...
Read MoreImplementing counting sort in JavaScript
In the given task, our aim is to create a counting sorting technique and implement this problem with the help of Javascript functionalities. What is Counting Sort? Counting sort is a non-comparison based sorting algorithm that works by counting the occurrences of each distinct element in the input array. It determines the position of each element in the sorted output by calculating how many elements are smaller than it. The algorithm works in several phases: Find the minimum and maximum values in the input array Create a count array to ...
Read MoreFunction to find out palindrome strings JavaScript
In this problem statement, our aim is to create a function to find out that the given string is palindrome with the help of Javascript functionalities. So for solving this problem first we need to understand the problem in simple terms. Understanding the Problem Statement We have given a string as an input string and our main aim is to check if the string is a palindrome string or not. If it is palindrome then return true otherwise return false. What is a Palindrome? A palindrome is a string that reads the same forwards and backwards. ...
Read More