Articles on Trending Technologies

Technical articles with clear explanations and examples

Find the Length of the Longest possible palindrome string JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 470 Views

Given a string s which consists of lowercase or uppercase letters, we are required to return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, "Aa" is not considered a palindrome here. For example, if the input string is "abccccdd", the output should be 7 because one longest palindrome that can be built is "dccaccd", whose length is 7. Algorithm Explanation The key insight is that a palindrome can have pairs of characters (which appear on both sides) plus at most one character in the middle. We ...

Read More

Write a program in JavaScript to check if two strings are anagrams of each other or not

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 15-Mar-2026 23K+ Views

Given two strings 'a' and string 'b', we have to check if they are anagrams of each other or not and return True/False. Two strings are anagrams if they contain the same characters with the same frequency, just rearranged. Input-1 − String a = "india" String b = "nidia" Output − True Explanation − Since the given string 'b' contains all the characters in the string 'a' with the same frequency, we will return True. Input-2 − String a = "hackathon" String b = "achcthoon" Output ...

Read More

Distributing Bananas Problem in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 428 Views

The distributing bananas problem involves giving bananas to people in a queue following a specific pattern. We start by giving 1 banana to the first person, 2 to the second, and so on. After reaching the end, we continue from the beginning with increasing amounts until all bananas are distributed. Problem Statement Suppose there are n people standing in a queue, we wish to distribute bananas to the people in the following way: We give 1 banana to the first person, 2 bananas to the second person, and so on until we give ...

Read More

How to remove elements from an array until the passed function returns true in JavaScript?

Imran Alam
Imran Alam
Updated on 15-Mar-2026 508 Views

In JavaScript, there are various ways to remove elements from an array until the passed function returns true. This tutorial explores three different approaches with practical examples. Understanding "Remove Until Function Returns True" This operation means collecting elements from the beginning of an array, stopping when a condition is met. It's similar to "taking elements while a condition is false" or "dropping elements until a condition is true". Using Array.prototype.filter() The filter() method creates a new array with elements that pass a test function. For removing elements until a condition is met, we filter elements that ...

Read More

How to create regular expression only accept special formula?

Rushi Javiya
Rushi Javiya
Updated on 15-Mar-2026 1K+ Views

Regular expressions are powerful patterns used to validate and match specific text formats. In this tutorial, we'll learn how to create regular expressions that validate mathematical formulas containing various operators and formats. Basic Formula Validation Let's start with a simple regular expression that accepts basic mathematical formulas with addition and subtraction operators. Syntax let regex = /^\d+([-+]\d+)*$/g; This regex accepts formulas like "10-13+12+23" with no spaces between operators and numbers. Regular Expression Breakdown ^ – Represents the start of the string \d+ – Matches one or more digits at the ...

Read More

Behavior of + operator in JavaScript to store large numbers?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 3K+ Views

JavaScript's + operator converts strings to numbers, but regular numbers have precision limits. For large integers beyond JavaScript's safe range, use BigInt() to avoid precision loss. The Problem with + Operator for Large Numbers JavaScript numbers use 64-bit floating point, which can safely represent integers up to Number.MAX_SAFE_INTEGER (2^53 - 1). Beyond this limit, the + operator causes precision loss: console.log("JavaScript's safe integer limit:"); console.log(Number.MAX_SAFE_INTEGER); // Small number - works fine var stringValue1 = "100"; console.log("Small number with + operator:"); console.log(+stringValue1); // Large number - precision loss var stringValue2 = "2312123211345545367"; console.log("Large number with ...

Read More

Add line break inside a string conditionally in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In JavaScript, you can add line breaks inside a string conditionally by checking character limits and replacing spaces with newline characters. This is useful for formatting text within specific width constraints. Problem Description We need to create a function breakString() that takes two parameters: a string to be broken and a threshold number representing the maximum characters per line. When the character count exceeds this limit and we encounter a space, we replace it with a line break. Algorithm Approach The solution iterates through the string while maintaining a character count. When the count reaches the ...

Read More

Picking the largest elements from multidimensional array in JavaScript

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 3K+ Views

Given a multidimensional array, we need to pick the largest elements from each subarray in JavaScript. The multidimensional arrays are arrays inside an array. Whenever there are arrays inside the array, it works as a multidimensional array. Following is a one-dimensional array: const arr = ["Welcome", "to", "tutorials", "point"]; const numbers = [1, 5, 12, 67, 99]; This is how a multidimensional array looks like: const array = [["Mike tyson", "Vijay"], ["ananya", "charmee"], ["Lion", "Tiger"]]; This is how we can access elements from a multidimensional array: ...

Read More

Two sum in BSTs in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 253 Views

We are required to write a JavaScript function that takes in the roots of two binary search trees, root1 and root2, as the first and the second argument respectively. The third argument to the function is number, target. Our function should return True if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target, false otherwise. Problem Example For example, if the input to the function is: const target = 23; ...

Read More

Obtaining maximum number via rotating digits in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 153 Views

We are required to write a JavaScript function that takes in a positive integer n and returns the maximum number we can get by performing only left rotations on the digits of the number. Problem Left rotation means moving the first digit to the end. For example, rotating 12345 once gives 23451, rotating again gives 34512, and so on. We need to find which rotation produces the largest number. Example Let's implement the solution to find the maximum number through left rotations: const num = 56789; const findMaximum = (num = 1) => ...

Read More
Showing 16351–16360 of 61,297 articles
Advertisements