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
Javascript Articles
Page 149 of 534
Finding minimum absolute difference within a Binary Search Tree in JavaScript
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 MoreFinding the third maximum number within an array in JavaScript
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 MoreKit-Kat array in JavaScript
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 MoreFinding nth digit of natural numbers sequence in JavaScript
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 MoreBeautiful Arrangement of Numbers in JavaScript
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 MoreForming the longest word in JavaScript
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 MoreSubarray sum with at least two elements in JavaScript
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 MoreImplementing a Binary Search Tree in JavaScript
A tree is a collection of nodes connected by edges, where each node holds data and references to its children. Binary Search Trees (BST) are a special type of binary tree that maintains a sorted order. What is a Binary Search Tree? A Binary Search Tree is a binary tree where nodes with lesser values are stored on the left, and nodes with higher values are stored on the right. This property makes searching, insertion, and deletion operations efficient. 25 ...
Read MoreDetermining rank on basis of marks in JavaScript
We are required to write a JavaScript function that takes in an array of numbers representing student marks and returns an array of ranks based on their performance. The function should assign rank 1 to the highest marks, rank 2 to the second highest, and so on. Each student's rank corresponds to their position when marks are sorted in descending order. Problem Statement Given an array of marks, we need to determine the rank of each student based on how their marks compare to others in the class. For example, if the input is: ...
Read MoreNext Greater Element in Circular Array in JavaScript
Circular Array An array in which the next element of the last element is the first element of the array is often termed as circular. This concept allows us to treat arrays as if they wrap around, where after the last index, we continue from the first index. Obviously, there exists no such mechanism to store data like this. Data will still be stored in continuous memory blocks, and circular arrays are more like a logical concept than physical reality. Problem We need to find the next greater element for each element in a circular array. The Next ...
Read More