Web Development Articles

Page 247 of 801

Distance of nearest 0 in binary matrix in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 289 Views

A binary matrix is an array of arrays containing only 0 or 1. We are required to write a JavaScript function that takes in a binary matrix as the only argument. Our function should create a new matrix containing the same number of rows and columns, and for each element of the original matrix the resulting matrix should contain that element's nearest distance from 0 in the original matrix. We have to keep in mind that while calculating distance it can move either horizontally or vertically and not diagonally. And it's guaranteed that the matrix contains at least ...

Read More

Reversing strings with a twist in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 281 Views

We are required to write a JavaScript function that takes in a string str as the first argument and an integer num as the second argument. Our function should reverse the first num characters for every 2 * num characters counting from the start of the string. If there are less than num characters left, we have to reverse all of them. If there are less than 2 * num but greater than or equal to num characters, then we have to reverse the first num characters and leave the others as original. Example Input and Output ...

Read More

Preparing encoding and decoding algorithms for shortening URLs in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 924 Views

URL shortening services like bit.ly and TinyURL take long URLs and convert them into shorter, more manageable links. This process involves encoding the original URL into a compact format and later decoding it back when accessed. To implement a basic URL shortening system in JavaScript, we need two main functions: encrypt() → takes the original URL and returns a shortened unique URL decrypt() → takes the shortened URL and converts it back to the original URL Basic Implementation Using Base64 Encoding Here's a simple approach using ...

Read More

Finding minimum absolute difference within a Binary Search Tree in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 268 Views

We are required to write a JavaScript function that takes in the root of a BST that holds some numerical data like this: 1 \ 3 / 2 The function should return the minimum absolute difference between any two nodes of the tree. For the above tree, the output should be: const output = 1; because |1 - 2| = |3 - 2| = 1 Understanding ...

Read More

Finding the third maximum number within an array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 256 Views

Finding the third maximum number in a JavaScript array requires handling duplicates and edge cases where fewer than three unique values exist. The task is to return the third largest unique number from an array. If fewer than three unique numbers exist, return the maximum number instead. Problem Example For the input array: [34, 67, 31, 87, 12, 30, 22] The unique numbers sorted in descending order are: [87, 67, 34, 31, 30, 22, 12] The third maximum is 34. Solution Approach The algorithm works by: ...

Read More

Kit-Kat array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 210 Views

In JavaScript, a Kit-Kat array is a custom array where numbers are replaced with specific strings based on divisibility rules. This pattern is similar to the classic FizzBuzz problem but with customizable divisors. Problem Statement Create a function that takes three parameters: a natural number num, and two divisors m and n. The function should return an array containing numbers from 1 to num with these replacements: Replace multiples of m with 'kit' Replace multiples of n with 'kat' Replace multiples of both m ...

Read More

Finding nth digit of natural numbers sequence in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 677 Views

In this problem, we need to find the nth digit in the infinite sequence formed by concatenating natural numbers: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12... When we remove commas and spaces, this becomes: "123456789101112..." and we need to find the digit at a specific position. Understanding the Problem The natural number sequence when concatenated forms: Position: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Digit: 1 2 3 4 5 6 7 8 9 ...

Read More

Beautiful Arrangement of Numbers in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 428 Views

A beautiful arrangement is a permutation of numbers from 1 to num where each position satisfies specific divisibility rules. This problem involves finding all valid arrangements using backtracking. Definition For an array with num integers from 1 to num, a beautiful arrangement requires that for each position i (1-indexed): The number at position i is divisible by i, OR i is divisible by the number at position i Problem Statement Write a JavaScript function that takes a number and returns the count of all possible ...

Read More

Forming the longest word in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 342 Views

We are required to write a JavaScript function that takes in a random English alphabet string, str, as the first argument and an array of strings, arr, as the second argument. The task of our function is to try deleting some characters from the string str and check which longest word can be formed that exists in the array arr as well. Our function should return the longest possible string. If there exists no such string, we should return an empty string. Problem Example For example, if the input to the function is: const ...

Read More

Subarray sum with at least two elements in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 247 Views

We need to write a JavaScript function that takes an array of integers and a target value, then checks whether there exists a continuous subarray of size at least 2 that sums up to a multiple of the target value. Problem Statement Given an array of integers and a target value k, return true if there exists a continuous subarray of size at least 2 that sums up to n*k (where n is any integer), otherwise return false. For example: Input: arr = [23, 2, 6, 4, 7], target = 6 Output: true ...

Read More
Showing 2461–2470 of 8,010 articles
« Prev 1 245 246 247 248 249 801 Next »
Advertisements