Found 6685 Articles for Javascript

JavaScript Program for Inserting a Node in a Linked List

Prabhdeep Singh
Updated on 24-Mar-2023 11:20:16

518 Views

Linked lists are data structures with varying lengths and any node can be deleted or added to the linked list. In this tutorial, we are going to implement a complete program for inserting a node in a linked list with space and time complexity. Let’s first understand the problem statement. Introduction to Problem In the given problem we are given a linked list and as we can change the size of the linked list by adding or removing a node from the linked list, we are going to add or insert a node in a linked list. In the linked ... Read More

JavaScript Program for Frequencies of even and odd numbers in a matrix

Prabhdeep Singh
Updated on 24-Mar-2023 11:19:11

107 Views

In this tutorial, we will implement a JavaScript program for finding the frequencies of even and odd numbers. We will be given a 2D matrix that is the size of MXN and we have to find the frequencies (means the count of element present) of all odd and even numbers present in the matrix. We will see two approaches, one will be the brute force approach (using for loops) and another will be the bitwise and operator approach. Introduction to Problem In this problem, we are given a 2d matrix that contains odd and even numbers in an unsorted manner ... Read More

JavaScript Program for Finding the Length of Loop in Linked List

Prabhdeep Singh
Updated on 24-Mar-2023 11:01:48

97 Views

In this program, we will be given a linked list that may consist of a loop and we have to find if the loop exists then what will be the size of the loop. Let’s a very famous approach to finding the length of a loop with the help of a code and discuss its time and space complexity. Introduction to Problem In this problem, as we have seen above we are given a linked list that may or may not contain a loop in it and we have to find the length of the loop if it exits ... Read More

JavaScript Program for Finding Length of a Linked List

Prabhdeep Singh
Updated on 24-Mar-2023 10:56:47

272 Views

A linked list is a linear data structure that can be a variable length and the length of the linked list can be changed, which was a problem in the array that the length of the array cannot be changed. In this article, we are going to find the length of a given linked list by implementing the code and going through the edge cases. We will use the while loop and the class concepts in this article. Introduction to Problem In the given problem we are given a linked list and first, we have to create the linked list ... Read More

JavaScript Program for Finding Intersection of Two Sorted Linked Lists

Prabhdeep Singh
Updated on 24-Mar-2023 10:53:38

165 Views

In this program, we are given two linked lists and we have to create a new linked list that will contain all the elements which are common in both of the lists as the lists are given sorted then we can use the concept of two pointers which are going to see in the article below. Introduction to Problem In the given problem we have to find the intersection of the given linked lists. Intersection means to get the common values from the given set of values, so here we have given two sorted linked lists from which we have ... Read More

JavaScript Program for Finding a Triplet from Three Linked Lists with a Sum Equal to a Given Number

Prabhdeep Singh
Updated on 24-Mar-2023 10:52:20

94 Views

In this article, we are going to implement a JavaScript program for finding a triplet from three linked lists with a sum equal to a given number. This problem is a kind of variation of the standard and famous three-sum problem but in a linked list manner. Let’s see the problem and implement its code along the key points of the problem. Introduction to Problem This problem is the variation of the standard problem of three sums where we are given three arrays and we have to find if there is any triplet present in the array with a sum ... Read More

JavaScript Program for Counting sets of 1s and 0s in a binary matrix

Prabhdeep Singh
Updated on 24-Mar-2023 10:50:57

226 Views

A binary matrix is a matrix that consists of only two digits as its name suggests and those two digits are 1 and 0. In this article, we will go through the code with the approach and the proper explanation to understand the concepts in a better way. In this tutorial, we are going to write a JavaScript program for counting the sets of 1s and 0s in a given binary matrix. Introduction to Problem In this problem, we are given a binary matrix and we have to find the sets that contain the same value in the row or ... Read More

JavaScript program for counting frequencies of array elements

Prabhdeep Singh
Updated on 24-Mar-2023 10:48:00

650 Views

Counting the frequencies means we have to count the number of times an element from the array appears in the given array. We can use some inbuilt data structures like maps to get the frequency or we can sort the array also to get the frequency of the array elements. We will discuss both approaches, let’s see both of them one by one − Sorting the Array In this approach, we are going to sort the array and check if the current element is the same as the previous one, if the current array is not the same then this ... Read More

JavaScript Program for Count Primes in Ranges

Prabhdeep Singh
Updated on 24-Mar-2023 10:24:37

3K+ Views

Prime numbers are numbers that have exactly two perfect divisors. We will see two methods to find the number of prime numbers in a given range. The first is using the brute force method and by this method time complexity is a bit high. Then we will improve this method and will go for the Sieve of the Eratosthenes algorithm to go with better time complexity. In this article, we are going to find the total number of prime numbers in the given range using the JavaScript programming language. Brute Force Method In this method first, we will learn how ... Read More

JavaScript Program to Check whether all the rotations of a given number are greater than or equal to the given number or not

Prabhdeep Singh
Updated on 24-Mar-2023 10:22:26

82 Views

In this article, we will go through a JavaScript program to check whether all the rotations of a given number are greater than or equal to the given number or not. We will write an algorithm and explain every step that what we are doing. The time complexity of the code that is going to discuss will be optimistic and space complexity will all be improved from one code to another. Introduction to Problem In the problem, we are given a number and we have to check for each rotation whether they all are greater than the current number or ... Read More

Advertisements