Javascript Articles

Page 12 of 534

JavaScript Program to Count rotations required to sort given array in non-increasing order

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 224 Views

We will be writing a program to count the number of rotations required to sort an array in non-increasing order. A rotation moves the first element to the end of the array. The program identifies where the array starts to break the non-increasing pattern and calculates the minimum rotations needed. Understanding the Problem For an array to be sorted in non-increasing order, each element should be greater than or equal to the next element. If we have a rotated sorted array, we need to find the rotation point and calculate how many positions we need to rotate to ...

Read More

JavaScript Program To Delete Alternate Nodes Of A Linked List

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 288 Views

We will be writing a JavaScript program to delete alternate nodes of a linked list. We will be utilizing a while loop to traverse the linked list while keeping track of the current node. In each iteration, we will skip every second node by linking the current node directly to the node after the next one, effectively removing alternate nodes from the list. Approach Start traversing from the head node of the linked list. For each node, check if both current node and its next node exist. Skip ...

Read More

JavaScript Program To Delete Nodes Which Have A Greater Value On Right Side

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 375 Views

We will implement a function to delete nodes in a linked list which have a greater value on their right side. The approach is to traverse the linked list from right to left and keep track of the maximum value encountered so far. For each node, we compare its value with the maximum value and delete the node if its value is less than the maximum value. Problem Understanding Given a singly linked list, we need to delete all nodes that have at least one node with a greater value to their right. For example, in the list ...

Read More

JavaScript Program to Find a triplet such that sum of two equals to third element

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 385 Views

We will be writing a JavaScript program that finds a triplet where the sum of two elements equals the third element. This program will be implemented using arrays and loop structures. We will iterate through the array and check for each combination of three elements if two elements sum up to the third. If we find such a triplet, we will return it immediately. Problem Understanding Given an array, we need to find three elements (a triplet) where a + b = c. For example, in array [1, 4, 45, 6, 10, 8], the triplet [4, 6, 10] ...

Read More

JavaScript Program to Find array sum using Bitwise OR after splitting given array in two halves after K circular shifts

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 272 Views

We will write a JavaScript program to find the sum of an array by using bitwise OR after splitting the given array into two halves after K circular shifts. Our program will perform the task by taking an array and an integer K as inputs. First, we will split the array into two halves after performing K circular shifts. Then, we will perform bitwise OR on both the halves to get a new array. Finally, we will find the sum of the new array obtained from the bitwise OR operation. Approach First, perform K ...

Read More

JavaScript Program to Find element at given index after a number of rotations

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 194 Views

When working with arrays in JavaScript, we often need to find elements after rotating the array. A rotation shifts all elements in a specific direction. This program demonstrates how to efficiently find an element at a given index after performing a number of right rotations without actually rotating the array. Understanding Array Rotations A right rotation shifts all elements one position to the right, with the last element moving to the first position. For example, rotating [1, 2, 3, 4, 5] right by 2 positions gives [4, 5, 1, 2, 3]. ...

Read More

JavaScript Program to Find k maximum elements of array in original order

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 247 Views

We will be using the JavaScript array sort method and slicing technique to find the k maximum elements of an array in their original order. Firstly, we sort the array in descending order, and then slice it from the beginning to the kth index to obtain the k maximum elements. By preserving the original order of the elements, the significance and context of the data remains intact, making it easier for us to analyze and interpret the results. Approach The approach to find k maximum elements of an array in original order can be described as follows − ...

Read More

JavaScript Program to Find Maximum number of 0s placed consecutively at the start and end in any rotation of a Binary String

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 218 Views

We will be writing a JavaScript program to find the maximum number of zeros placed consecutively at the start and end of any rotation of a binary string. Our program will take a binary string as input and return the maximum number of zeros that can appear consecutively when considering all possible rotations. The key insight is that we need to check all rotations of the binary string and count consecutive zeros at both the beginning and end of each rotation, then find the maximum total count. Approach To find the maximum number of zeros placed consecutively ...

Read More

JavaScript Program to Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 512 Views

In JavaScript, we need to find the maximum value of Sum(i*arr[i]) by rotating an array. This problem can be solved efficiently using a mathematical approach that avoids checking all possible rotations. Problem Understanding Given an array, we can rotate it left or right. For each rotation, we calculate the sum of (index × element). Our goal is to find the maximum possible sum across all rotations. For example, with array [1, 20, 2, 10]: Original: (0×1) + (1×20) + (2×2) + (3×10) = 54 Rotate 1: (0×20) + (1×2) + (2×10) + (3×1) = 25 Rotate ...

Read More

JavaScript Program to Find median in row wise sorted matrix

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 239 Views

We will be describing the process of finding the median in a row-wise sorted matrix using JavaScript. First, we will traverse the matrix to gather all the elements into a single array. Then, we will sort the array to find the middle value, which will be our median. In case of an even number of elements, the median will be the average of the two middle values. Approach 1: Simple Array Concatenation Method Given a row-wise sorted matrix, the median can be found by the following approach − Combine all rows into a ...

Read More
Showing 111–120 of 5,340 articles
« Prev 1 10 11 12 13 14 534 Next »
Advertisements