Count Pairs with Given Sum in JavaScript

Ravi Ranjan
Updated on 06-Jun-2025 19:17:34

1K+ Views

To count pairs with given sum, is a common problem asked in job interviews and is often used in many real-world applications such as cryptography and data compression. In this article we are having an array and a target sum value, our task is to write a Javascript program to count pairs with given sum. Example Input: arr = [1, 2, 3, 5, 6, 7, 9] sum = 8 Pairs = (1, 7), (2, 6), (3, 5) Output: Count: 3 Approaches to Count Pairs with Given Sum Here is a list of ... Read More

JavaScript Program for the Third Largest Element in an Array

Ravi Ranjan
Updated on 06-Jun-2025 19:17:02

792 Views

For the third largest element in an array of distinct elements, we will discuss three different approaches. We will improve efficiency with each approach and discuss their complexities. In this article we are having an array of distinct elements, our task is to find third largest element in an array of distinct elements in Javascript. Users must be familiar with array, loops and conditional statement. Example Input: arr = [2, 5, 8, 1, 4, 10, 7] => Highest: 10, second highest: 8, third highest: 7 Output: 7 Approaches for Third Largest Element in Array ... Read More

JavaScript Program for Counting Frequencies of Array Elements

Ravi Ranjan
Updated on 06-Jun-2025 19:16:49

1K+ Views

Counting frequencies of array elements means we have to count the number of times an element from the array appears in the given array. We will be discussing five different approaches to achieve this. We can use some inbuilt data structures or external libraries for easy implementation. In this article we are having an array with duplicate elements, our task is to count frequencies of array elements in JavaScript. Users must be familiar with array and it's functions, JavaScript methods and function, loops, conditional statement and Javascript objects. Approaches to Count Array Elements Frequencies Here is a list of ... Read More

Find Common Elements in Two Sorted Arrays

Ravi Ranjan
Updated on 06-Jun-2025 19:16:37

504 Views

To find common elements in two sorted arrays using JavaScript, we will be discussing various approaches. Common element refers to element which is present in both the arrays. First, we will try brute force approach and then we will optimize our code to improve the time complexity. In this article we are having two sorted arrays, our task is to find common elements in two sorted arrays. Users must already know about JavaScript arrays, its function and operations on arrays, loops, searching technique and conditional statement. Example Input: arr1 = [1, 2, 3, 4, 5] ... Read More

Search an Element in a Sorted Rotated Array in C++

Ravi Ranjan
Updated on 06-Jun-2025 19:16:12

1K+ Views

A sorted and rotated array is an array that is sorted in ascending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. The array can be said to be split into two halves and each half is a sorted array. For example: {5, 6, 7, 1, 2, 3} is a sorted and rotated array and {5, 6, 7, 8, 2, 5, 4, 5} is not a sorted and rotated array. In this article, we have an array of integers. Our task is ... Read More

Check If an Array is Sorted and Rotated in C++

Ravi Ranjan
Updated on 06-Jun-2025 19:15:03

2K+ Views

A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. The array can be said to be split into two halves and each half is a sorted array. For example: {5, 6, 7, 1, 2, 3} is a sorted and rotated array and {5, 6, 7, 8, 2, 5, 4, 5} is not a sorted and rotated array. In this article, our task is to check if the ... Read More

Mirror of Matrix Across Diagonal in JavaScript

Ravi Ranjan
Updated on 06-Jun-2025 19:14:12

399 Views

To write a javascript program for mirror of matrix across diagonal, we will be discussing two approaches with their code example and explanation of code. In this article we are having a 2D matrix. Our task is to write a JavaScript program for mirror of matrix across diagonal. Example Input: matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] Output: [[1, 4, 7], [2, 5, 8], [3, 6, 9]] Approaches ... Read More

Find Lexicographically Minimum String Rotation in JavaScript

Ravi Ranjan
Updated on 06-Jun-2025 19:13:41

604 Views

To find lexicographically minimum string rotation in Javascript, we will understand two different approaches in this article. A lexicographically minimum rotation of a string is the smallest string that can be obtained by rotating the original string any number of times in lexicographical order. By lexicographical order it means dictionary order such as: a < b, ab < ac. In this article we are having a string. Our task is to write a JavaScript program to find lexicographically minimum string rotation. Example Input: bba All lexicographical order are: bba, bab, abb Output: Smallest lexicographical rotation: abb ... Read More

Convert 24 Hours Format to 12 Hours in JavaScript

Ravi Ranjan
Updated on 06-Jun-2025 19:13:26

2K+ Views

To convert 24 hours format to 12 hours in Javascript, we have discussed two different approaches. In this article we are having time in 24 hours format, our task is to write a JavaScript program to convert 24 hours format to 12 hours. Approaches to Convert 24-hours format to 12-hours Here is a list of approaches to write a JavaScript program to convert 24 hours format to 12 hours which we will be discussing in this article with stepwise explanation and complete example codes. Using if-else Statement Using Date Object ... Read More

Rotate a Matrix by 180 Degrees in JavaScript

Ravi Ranjan
Updated on 06-Jun-2025 19:13:01

367 Views

To rotate a matrix by 180 degrees, can be achieved using various approaches. We have discussed three different approaches in this article with stepwise explanation of codes and examples. In this article, we are having a 2D square matrix, our task is to write a JavaScript program to rotate a matrix by 180 degrees. Example Input: matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]] Output: [[16, 15, 14, 13], [12, 11, 10, 9], [8, 7, 6, 5], [4, 3, 2, 1]] Approaches to Rotate a Matrix ... Read More

Advertisements