Found 8895 Articles for Front End Technology

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

AmitDiwan
Updated on 15-Mar-2023 14:55:41

266 Views

We will be using a mathematical approach to find the maximum value of the sum of the product of the index and the value of the elements in the array. By rotating the array, we can maximize this sum by placing the maximum value of the array at the index with the maximum product. The algorithm we will be using involves finding the sum of the products of the index and values of the elements, then adding the difference between this sum and the product of the length of the array and the sum of the index values to this ... 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
Updated on 15-Mar-2023 14:53:07

85 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 will return the maximum number of zeros that are placed at the start and end in any rotation of the given string. To solve this problem, we will be using string manipulation techniques to manipulate the input string and find the required output. In the next step, we will be rotating the input string and counting the number of zeros placed at ... Read More

JavaScript Program to Find maximum element of each row in a matrix

AmitDiwan
Updated on 15-Mar-2023 14:50:12

308 Views

We will write a program that utilizes the future continuous tense in order to find the maximum element of each row in a given matrix. This will involve looping through each row of the matrix and comparing the elements to find the maximum value. In order to implement this solution, we will use built-in functions such as Math.max() and loops to traverse the matrix and obtain the desired result. By the end of our program, we will have a solution that will be able to handle matrices of any size and provide the maximum value of each row in an ... Read More

JavaScript Program to Find Lexicographically minimum string rotation

AmitDiwan
Updated on 15-Mar-2023 14:44:31

366 Views

We will be finding the lexicographically minimum string rotation in JavaScript. The method involves concatenating the original string with itself and then using the built-in 'sort' function to sort the concatenated string in ascending order. Finally, we will be returning the smallest substring of the sorted concatenated string which has the same length as the original string. This will be the lexicographically minimum string rotation. We will be implementing this logic by making use of string manipulation techniques and built-in functions available in JavaScript. The result of our implementation will be a string that represents the lexicographically minimum rotation of ... Read More

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

AmitDiwan
Updated on 15-Mar-2023 14:43:17

80 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 − Create ... Read More

JavaScript Program to Find if there is a subarray with 0 sum

AmitDiwan
Updated on 15-Mar-2023 14:36:11

349 Views

We, as developers, are often asked to find if there is a subarray with 0 sum in an array. This can be done by using the concept of prefix sum. We will keep track of the sum of elements of the subarray seen so far and store it in a hash map. If the sum is seen before, it means that the subarray with this sum exists and has 0 sum. We will be continuously updating the hash map with the sum of elements seen so far. This way, we can determine if there is a subarray with 0 sum ... Read More

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

AmitDiwan
Updated on 15-Mar-2023 14:33:24

68 Views

We will be implementing a JavaScript program to find an element at a given index after a number of rotations. This program will require us to perform rotations on an array and then return the element present at the specified index. To accomplish this task, we will be using the modulo operator to calculate the new index after each rotation. The future continuous tense will be used throughout the explanation. In the program, we will be taking the input of the array, the number of rotations, and the index. We will then perform the rotations by using the modulo operator ... Read More

JavaScript Program to Find difference between sums of two diagonals

AmitDiwan
Updated on 15-Mar-2023 14:31:38

295 Views

We will be finding the difference between the sums of two diagonals of a square matrix. Firstly, we will calculate the sum of the elements present in the first diagonal by traversing the matrix starting from the top left corner to the bottom right corner. Secondly, we will calculate the sum of the elements present in the second diagonal by traversing the matrix starting from the top right corner to the bottom left corner. Finally, we will subtract the sum of the second diagonal from the sum of the first diagonal to get the difference between the two diagonals. Approach ... Read More

JavaScript Program to Find closest number in array

AmitDiwan
Updated on 15-Mar-2023 14:30:35

2K+ Views

We will write a JavaScript program to find the closest number in an array by comparing each element with the target number and keeping track of the closest one. The program will use a loop to go through each element in the array and use a conditional statement to compare the difference between the target number and the current element. If the difference is smaller than the current closest difference, we will update the closest number. The result of this program will be the closest number to the target in the given array. Approach This program finds the closest number ... Read More

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

AmitDiwan
Updated on 15-Mar-2023 14:29:03

143 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 circular shifts on the given ... Read More

Advertisements