Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 9 of 17

Comparing integers by taking two numbers in JavaScript

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

Comparing integers is a fundamental operation in JavaScript programming. This tutorial demonstrates how to compare two integers and determine their relationship using JavaScript's comparison operators. Understanding the Problem Integer comparison involves determining the relationship between two numbers - whether one is greater than, less than, or equal to another. This operation is essential for sorting algorithms, conditional logic, and data validation. For example, comparing 15 and 10 tells us that 15 is greater than 10. Comparison Operators in JavaScript ...

Read More

Queue Reconstruction by Height in JavaScript

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

The Queue Reconstruction by Height problem involves arranging people in a queue based on their height and the number of taller people in front of them. Each person is represented as [h, k] where h is height and k is the count of people in front with height ≥ h. Understanding the Problem Given an array of people where each person is represented by [height, k], we need to reconstruct the queue. The key insight is that taller people don't affect the positioning of shorter people, so we can process people from tallest to shortest. For example, ...

Read More

Check if string ends with desired character in JavaScript

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

In JavaScript, you can check if a string ends with a specific character using several built-in methods. The most common approaches are using endsWith(), charAt(), or bracket notation. Understanding the Problem We need to determine if a given string ends with a specific character. For example, checking if "Hello World!" ends with "!" should return true, while checking if "Hello World." ends with "!" should return false. Using endsWith() Method (Recommended) The endsWith() method is the most straightforward approach: const str1 = "Hello, Tutorials Point!"; const str2 = "Hello, World."; const desiredChar = "!"; ...

Read More

Remove number from array and shift the remaining ones JavaScript

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

In this problem statement, our task is to write a function to remove numbers from an array and shift the remaining elements using JavaScript. We'll explore multiple approaches including the filter method, for loops, and in-place modification to achieve this functionality. Understanding the Problem We need to create a function that removes all occurrences of a given number from an array and shifts the remaining items to fill the gaps. For example, given array [1, 2, 3, 4, 2, 5] and number 2, the result would be [1, 3, 4, 5] with all instances of 2 removed and ...

Read More

Pair whose sum exists in the array in JavaScript

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

In this article we will see how to find pairs of items in an array whose sum equals another element present in the same array. We'll use JavaScript to implement an efficient algorithm for this problem. Understanding the Problem The problem is to find pairs of numbers (a, b) in an array where a + b = c, and c is also present in the array. For example, in array [1, 2, 3, 4, 5], the pair (1, 2) has sum 3, which exists in the array. Approach Using Hash Set We'll use a Set data ...

Read More

Reversing array without changing the position of certain elements JavaScript

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

In this problem, we need to reverse an array while keeping certain elements in their original positions. This requires tracking preserved element positions and carefully swapping only the non-preserved elements. Understanding the Problem The goal is to reverse an array but preserve specific elements at their original positions. For example, if we have array [1, 2, 3, 4, 5, 6] and want to preserve elements [2, 4, 6], the result should be [5, 2, 3, 4, 1, 6] instead of a complete reversal. Algorithm Approach The solution involves: Track indices of elements to preserve Create ...

Read More

Factorize a number in JavaScript

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

In JavaScript, factorizing a number means finding all the prime factors that multiply together to form the original number. This is a fundamental mathematical operation used in cryptography, number theory, and various algorithms. Understanding Prime Factorization Prime factorization breaks down a number into its basic building blocks - prime numbers. For example, 36 = 2 × 2 × 3 × 3, where 2 and 3 are prime factors. We need to find all prime numbers that divide the given number without leaving a remainder. Algorithm Approach The efficient approach iterates from 2 to the square root ...

Read More

Split a range of number to a specific number of intervals JavaScript

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

In this problem statement, our task is to write a function that splits a range of numbers into a specific number of intervals using JavaScript. We need to provide the start value, end value, and the number of intervals. Understanding the Problem The problem requires creating a function that divides a numerical range into equal intervals. The inputs are the starting number, ending number, and desired number of intervals. The output should be an array of subarrays, where each subarray represents an interval with its start and end values. For example, if the range is from 0 ...

Read More

Finding the largest and smallest number in an unsorted array of integers in JavaScript

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

In JavaScript, finding the largest and smallest numbers in an unsorted array is a common programming task. We can efficiently solve this using a linear scan approach without sorting the entire array. Understanding the Problem Given an unsorted array of integers, we need to find both the minimum and maximum values. For example, in the array [11, 21, 14, 32, 20, 12], the smallest number is 11 and the largest is 32. The challenge is to find these values efficiently without sorting the array first. Method 1: Linear Scan Approach The most straightforward approach uses a ...

Read More

JavaScript Total subarrays with Sum K

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

In this problem, we need to find the total number of continuous subarrays within an array that have a sum equal to a given value K using JavaScript. Understanding the Problem Given an array of integers and a target sum K, we need to count all possible subarrays whose elements sum up to K. A subarray is a contiguous sequence of elements within an array. For example, if we have array [1, 2, 3, 4, 5] and K = 6, the subarrays with sum 6 are [1, 2, 3] and [2, 4], giving us a count of 2. ...

Read More
Showing 81–90 of 163 articles
« Prev 1 7 8 9 10 11 17 Next »
Advertisements