Front End Technology Articles

Page 125 of 652

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

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 389 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 274 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 196 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 250 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 227 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 523 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 243 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

JavaScript Program to Find Mth element after K Right Rotations of an Array

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 201 Views

We are writing a JavaScript program to find the mth element after k right rotations of an array. Instead of actually rotating the array, we can calculate the final position mathematically for optimal performance. Understanding Right Rotations In a right rotation, elements move to the right, and the last element wraps around to the first position. For example, rotating [1, 2, 3, 4, 5] right by 2 positions gives [4, 5, 1, 2, 3]. Mathematical Approach The key insight is that we don't need to perform actual rotations. We can calculate where the mth element will ...

Read More

JavaScript Program to Find the Longest Bitonic Subsequence | DP-15

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 499 Views

We will be finding the longest bitonic subsequence in an array using dynamic programming. A bitonic subsequence is a sequence which is first increasing, then decreasing. To find the longest bitonic subsequence, we will use a two-step approach: first find the longest increasing subsequence ending at each position, then find the longest decreasing subsequence starting from each position. What is a Bitonic Subsequence? A bitonic subsequence has two parts: Increasing part: Elements are in ascending order Decreasing part: Elements are in descending order For example, in [1, ...

Read More

JavaScript Program to Find the subarray with least average

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 263 Views

We are going to write a program that will find the subarray with the least average. To do this, we will iterate through the array and keep track of the current subarray and its sum. For each element, we will calculate the average of the current subarray and compare it with the minimum average we have seen so far. If it is lower, we will update the minimum average and the start and end indices of the subarray. At the end of the iteration, we will return the subarray with the least average. Approach To find the subarray ...

Read More
Showing 1241–1250 of 6,519 articles
« Prev 1 123 124 125 126 127 652 Next »
Advertisements