Found 10483 Articles for Web Development

JavaScript Program to Generate a matrix having sum of secondary diagonal equal to a perfect square

AmitDiwan
Updated on 15-Mar-2023 15:17:28

237 Views

We will write a JavaScript program that generates a matrix with the sum of the secondary diagonal being a perfect square. Our program will use nested loops to traverse the matrix and calculate the sum of the secondary diagonal elements. We will then use the Math.sqrt() method to find the square root of the sum and check if it is a whole number. If it is, we will consider the sum to be a perfect square. Approach The approach to generate a matrix with the sum of secondary diagonal equal to a perfect square is as follows − Create ... Read More

JavaScript Program to Form coils in a matrix

AmitDiwan
Updated on 15-Mar-2023 15:15:13

228 Views

We will be using JavaScript to form coils in a matrix. The process involves manipulating the elements of the matrix to create a spiral pattern. This can be achieved by changing the direction of traversal, keeping track of the visited elements, and adjusting the indices accordingly. We will be continuously working on the logic to make sure that the program runs smoothly and efficiently to produce the desired output. Approach One approach to form coils in a matrix using JavaScript would be the following − Define the size of the matrix. Initialize the matrix with zeros. Use nested loops ... Read More

JavaScript Program to Find the subarray with least average

AmitDiwan
Updated on 15-Mar-2023 15:13:18

197 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 with the ... Read More

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

AmitDiwan
Updated on 15-Mar-2023 15:10:30

406 Views

We will be finding the longest bitonic subsequence in each 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, we will find the longest increasing subsequence in the given array, then we will find the longest decreasing subsequence in the reverse of the given array. Finally, we will add the lengths of both the subsequences and subtract 1 to exclude the common element in the middle. Approach A bitonic sequence is a sequence that first increases and then decreases. The ... Read More

JavaScript Program to Find Simple Interest

AmitDiwan
Updated on 29-Nov-2024 15:09:38

9K+ Views

To find simple interest in javascript, we will find the product of principal amount, rate of interest(%) and time period. Simple intrest is a quick and easy method to find the intrest charge or extra amount paid by borrower to lender on certain amount of principal within a time period. In this article we are given a data of principal, rate and time, our task is to write a JavaScript program to find simple interest. Users must be familiar with the formula to calculate the simple interest, arithemetic operators in javascript and javascript functions. Formula: Simple ... Read More

JavaScript Program to Find Perimeter of a Triangle

Disha Verma
Updated on 17-Mar-2025 12:32:54

872 Views

The perimeter of a triangle is the sum of the lengths of its three sides. You can find the perimeter of a triangle using JavaScript by finding the sum of all sides of the triangle, as the perimeter of the triangle refers to the sum of all three sides of the triangle, i.e., perimeter = a + b + c. To find the perimeter of a triangle using JavaScript, we need to write a function that calculates the sum of three sides of a triangle and returns the triangle's perimeter as an output. In this article, we will understand the ... Read More

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

AmitDiwan
Updated on 15-Mar-2023 15:02:00

125 Views

We are writing a JavaScript program to find the mth element after k right rotations of an array. Firstly, we will take the input for the array, m and k. Then, we will use a loop to perform the right rotations. In each iteration of the loop, we will move the last element of the array to the first position. We will continue this loop for k times to get the rotated array. Finally, we will return the mth element of the rotated array as the result. Approach The approach for finding the mth element after k right rotations of ... Read More

JavaScript Program to Find median in row wise sorted matrix

AmitDiwan
Updated on 15-Mar-2023 15:00:46

183 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 Given a row-wise sorted matrix, the median can be found by the following approach − Combine all rows into a single sorted array. Find the middle element(s) of the combined array, ... Read More

JavaScript Program to Find Maximum value possible by rotating digits of a given number

AmitDiwan
Updated on 15-Mar-2023 14:59:32

353 Views

We will be writing a program to find the maximum value possible by rotating the digits of a given number. We will be using a loop to break down the number into individual digits and rearrange them in a way that gives us the maximum value. The loop will continuously rotate the digits and keep track of the highest value obtained until all possible rotations have been evaluated. The maximum value obtained from this process will then be returned as the result. Approach To find the maximum possible value by rotating digits of a given number, follow these steps − ... Read More

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

417 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

Advertisements