Web Development Articles

Page 248 of 801

Implementing a Binary Search Tree in JavaScript

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

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 More

Determining rank on basis of marks in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 964 Views

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 More

Next Greater Element in Circular Array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 360 Views

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

Finding Mode in a Binary Search Tree in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 395 Views

Mode of a set of data is the number that occurs most frequently. For instance, 3 is the mode of dataset [2, 3, 1, 3, 4, 2, 3, 1] as it appears three times, more than any other number. Binary Search Tree A Binary Search Tree (BST) is a tree data structure where: The left subtree of a node contains only nodes with keys less than or equal to the node's key. The right subtree of a node contains only nodes with keys greater than or equal to the node's ...

Read More

Traversing Diagonally in a matrix in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 946 Views

In JavaScript, traversing a matrix diagonally means moving through the elements in a zigzag pattern from top-left to bottom-right. This technique is useful for various algorithms including matrix processing and image manipulation. Problem Statement We need to write a JavaScript function that takes a square matrix (array of arrays with equal rows and columns) and traverses it diagonally, creating a new array with elements in the order they were encountered. For example, given this input matrix: const arr = [ [1, 2, 3], [4, 5, 6], ...

Read More

Ways to get to a specific sum in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 190 Views

Problem We are required to write a JavaScript function that takes in an array of integers, arr, as the first argument and a single integer, target, as the second argument. For each integer in the array, our function can either assign '+' or '-' to it. Our function should find out how many ways in total exist to assign '+', '-' to make the sum of integers of the array equal to the target sum. For example, if the input to the function is: const arr = [1, 1, 1, 1, 1]; const target = ...

Read More

Consecutive ones with a twist in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 243 Views

We are required to write a JavaScript function that takes in a binary array (an array that consists of only 0 and 1), arr, as the only argument. Our function should find the maximum number of consecutive 1s in this array if we can flip at most one 0. Problem Statement Given a binary array, find the maximum number of consecutive 1s we can achieve by flipping at most one 0 to 1. For example, if the input array is: [1, 0, 1, 1, 0] Then the output should be: 4 ...

Read More

Finding the smallest good base in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

For an integer num, we call k (k >= 2) a good base of num, if all digits of num base k are 1. For instance: 13 base 3 is 111, hence 3 is a good base for num = 13 Problem We are required to write a JavaScript function that takes in string str that represents a number as the only argument. The function should return the string representation of the smallest possible number which is a good base for str. For example, if the input to the function is: const str = ...

Read More

Formatting Software License Key in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 285 Views

Problem We need to write a JavaScript function that formats a software license key by reorganizing alphanumeric characters into groups of a specified length, separated by dashes. The function takes a string containing alphanumeric characters and dashes, removes existing dashes, converts all letters to uppercase, and regroups the characters. The requirements are: Remove all existing dashes from the input string Convert all lowercase letters to uppercase Group characters into sections of length K (except the first group, which can be shorter but must contain at least one character) Separate groups with dashes Example Input and ...

Read More

Magical String: Question in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 559 Views

A magical string consists of only '1' and '2' characters and has a unique property: the sequence of consecutive character group lengths generates the string itself. Understanding the Magical String The magical string starts as "1221121221221121122..." where grouping consecutive characters reveals the pattern: Original: 1 22 11 2 1 22 1 22 11 2 11 22 ...... Lengths: 1 2 2 1 1 2 1 2 2 1 2 2 ...... Notice how the length sequence (1, 2, 2, 1, 1, 2, 1, 2, 2, 1, ...

Read More
Showing 2471–2480 of 8,010 articles
« Prev 1 246 247 248 249 250 801 Next »
Advertisements