Nikitasha Shrivastava

Nikitasha Shrivastava

163 Articles Published

Articles by Nikitasha Shrivastava

Page 5 of 17

Common Character Count in Strings in JavaScript

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

In JavaScript, finding common characters between two strings involves counting how many characters appear in both strings. This is useful for text analysis, similarity comparisons, and string manipulation tasks. Understanding the Problem The goal is to count common characters between two strings, considering frequency. For example, if we have "abaac" and "baaaa", the common characters are 'a' (appears 3 times in first string, 4 times in second, so we count 3) and 'b' (appears 1 time in both, so we count 1), giving us a total of 4 common characters. Algorithm Step 1: Create a function ...

Read More

Get key from value in JavaScript

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

In JavaScript, finding a key from its corresponding value in an object requires iterating through the object's key-value pairs. Unlike accessing values by keys (which is direct), reverse lookup needs a search operation. Understanding the Problem Given a JavaScript object and a value, we need to find the key that maps to that value. For example: { key1: 'value1', key2: 'value2', key3: 'value3' } If we search for 'value2', we should get 'key2' as the result. Using Object.entries() and find() The most efficient ...

Read More

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 281 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 267 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 209 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 350 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 636 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 893 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
Showing 41–50 of 163 articles
« Prev 1 3 4 5 6 7 17 Next »
Advertisements