Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Prabhdeep Singh
Page 4 of 17
JavaScript Program for Maximum difference between groups of size two
In this program, we are given an array of integers with even length. We need to form groups of size two using array elements, then find the maximum difference between the group with the highest sum and the group with the lowest sum. Problem Statement Given an array of even length, we must partition it into groups of size two. Our goal is to find the maximum possible difference between the sum of any two groups. This means finding the highest sum group and the lowest sum group, then returning their difference. Examples Example 1: ...
Read MoreJavaScript Program for Maximum equilibrium sum in an array
The equilibrium sum of an array is found at an index where the sum of elements from the start to that index (inclusive) equals the sum of elements after that index. When multiple equilibrium points exist, we need to find the maximum sum among them. Problem Statement Given an array, find the maximum equilibrium sum where: Left sum includes elements from index 0 to current index (inclusive) Right sum includes elements after the current index (exclusive) Left sum equals right sum at the equilibrium point Example ...
Read MoreJavaScript Program for Print all triplets in sorted array that form AP
AP is the arithmetic progression in which the difference between two consecutive elements is always the same. We will print all the triplets in a sorted array that form AP using three approaches: Naive approach, binary search method and two-pointer approach. Introduction to Problem In this problem we are given a sorted array meaning all the elements are in increasing order. We have to find three elements which are part of the array and form an AP. For example − Given array: [1, 5, 2, 4, 3] From the given array we have triplets like [2, ...
Read MoreJavaScript Program for Printing Reverse of a Linked List Without Actually Reversing
Linked lists are linear data structures with their memory not being in a consecutive manner. We will write a complete code in JavaScript with different approaches and examples to understand the process better. Introduction to Problem In the given problem, we are given a linked list and we have to print all of its elements in reverse order, but we don't have to reverse the given linked list. For example − Given linked list: 1 2 3 4 5 6 Result: 6 5 4 3 2 1 We will use two methods ...
Read MoreJavaScript Program for Products of ranges in an array
We will be given an array and we have to answer some queries related to the given range that is from a given starting index to the ending point or index we have to return the product of the elements in that range. We will see some approaches in this article to implement the above problem in JavaScript with the explanation. Introduction to Problem We are given an array and some queries, in each query we will be given some ranges by indicating the first and the last index of the range and we have to answer the ...
Read MoreJavaScript Program to Cyclically Rotate an Array by One
To cyclically rotate an array by one means shifting the value present at each index to their left or right by one. In this article, we are having an array and our task is to write a JavaScript program to cyclically rotate an array by one. Users must be familiar with JavaScript loops and array operations. Original Array: 1 2 3 ...
Read MoreJavaScript Program for Queries to find the maximum sum of contiguous subarrays of a given length in a rotating array
Rotating array means we will be given a number and we have to move the elements of the array in cyclic order in either the right or left direction. Here we are not specified so we will use the right rotation as the standard and after the given number of rotations, we will return the subarrays with the maximum sum. We will see the code with the proper explanation in the article. Introduction to Problem In this problem, we are given an array that contains the integers and another array that contains the pairs of queries. Each index ...
Read MoreJavaScript Program for Quicksort On Singly Linked List
The singly-linked list is a linear data structure that consists of nodes. Each node contains data and a pointer to the next node, which holds the memory address of the next node since memory allocation for nodes is not continuous. Sorting arranges elements of a data structure like linked lists or arrays in a specific order, typically ascending. In this article, we'll implement the quicksort algorithm on a singly linked list using JavaScript. Introduction to Problem QuickSort is a divide-and-conquer sorting algorithm that uses recursion. It has an average time complexity of O(N * log(N)), making it ...
Read MoreJavaScript Program for Range LCM Queries
LCM stands for the Least Common Multiple, and the LCM of a set of numbers is the smallest positive integer that is divisible by all the numbers in the given set. In this article, we will implement a JavaScript program to handle range LCM queries efficiently. Problem Statement We are given an array of integers and another array of queries. Each query contains a pair of indices representing a range in the original array. For each query, we need to calculate the LCM of all elements within that range. For example, if the array is [1, 2, ...
Read MoreJavaScript Program for Range sum queries for anticlockwise rotations of Array by K indices
Anticlockwise rotation of an array means rotating all the elements of the given array to their left side by the given number of indexes. In this article, we will implement a JavaScript program for range sum queries for anticlockwise rotations of the array by k indices. Introduction to Problem In this problem, we are given an array that will contain some integers and another array that will contain the values in the pairwise form. Each pair will be the number of rotations we need for the current query and after a given number of rotations, we will be ...
Read More