Found 6710 Articles for Javascript

JavaScript Program To Add Two Numbers Represented By Linked Lists- Set 1

Prabhdeep Singh
Updated on 04-May-2023 11:02:09

262 Views

Adding two numbers is an easy task but could be tricky if the numbers are given in the form of the linked list. Each node of the linked list contains the digit of the number it represents in a continuous manner from the first node to the last node. We will be given two linked lists representing two different numbers and we have to add them and return the third number in the form of a linked list. Input 1 -> 2 -> 3 -> null 3 -> 2 -> 4 -> null Output 4 -> 4 -> 7 ... Read More

JavaScript Program to Check horizontal and vertical symmetry in binary matrix

Alshifa Hasnain
Updated on 20-Dec-2024 11:33:30

496 Views

In this article, we will learn to create a program to check both horizontal and vertical symmetry in a binary matrix in JavaScript. A binary matrix is a 2-D array that consists of one and zero only as the elements in each cell. Horizontal symmetry of a binary matrix means if the first row is the same as the last row, the second row is the same as the second last row, and so on. What are symmetry matrices?  Symmetry in matrices refers to how the values in the matrix mirror themselves along an axis. In the case of a ... Read More

JavaScript Program for Writing A Function To Get Nth Node In A Linked List

Prabhdeep Singh
Updated on 04-May-2023 10:58:19

200 Views

Linked list is a linear data structure and all the nodes are connected to each other by storing the address of the next node. To find the nth node in a linked list means to get the value present at the nth node of the given linked list and that can be done by two methods that are iterative and recursive method. Example Given linked list: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> null Node to find: 3 Output 3 Explanation: The value present at the third node is 3. Iterative Approach ... Read More

JavaScript Program to Check if Strings are Rotations of Each Other or Not

Prabhdeep Singh
Updated on 21-Jan-2025 09:48:14

721 Views

To check if strings are rotations of each other or not, it means that two strings can be rotated to either the right or left direction to obtain the other string. In the right rotation characters of the string shift to their following index and for the zeroth index, it takes the character of the last index assuming the string is in a circle. Left rotation is similar to right rotation but in the opposite direction. In this article We are having two strings and we have to write a JavaScript program to check whether by rotating the characters of ... Read More

JavaScript Program to Check if Matrix is Upper Triangular

Ravi Ranjan
Updated on 06-Jun-2025 19:36:38

232 Views

To check if matrix is upper triangular matrix, we check if all the elements below the main diagonal is 0. We are going to discuss two different approaches and compare their complexities. In this article we are having a 2D square matrix, our task is to write a JavaScript program to check if matrix is upper triangular matrix. Users must be familiar with upper triangular matrix, nested for loop, conditional statement and javascript methods. Example Input: Matrix: [[1, 2, 3, 4], 0, 5, 6, 7], ... Read More

JavaScript Program to check if the matrix is lower Triangular

Prabhdeep Singh
Updated on 13-Apr-2023 15:30:14

131 Views

A matrix can be defined as a 2D array that stores elements in it and mathematically it stores the numbers in it. A Lower triangular matrix is a squared matrix that has the same number of rows and columns and all the elements that are present above the main diagonal passing from the first cell (present at the top-left) towards the last cell (present at the bottom-right) are zero. We will implement a proper code with explanation and discussion over time and space complexity. Example Input 1: mat = [ [ 1, 0, 0, 0], [ 2, ... Read More

JavaScript Program to Check if it is possible to sort the array after rotating it

Prabhdeep Singh
Updated on 13-Apr-2023 15:28:38

118 Views

Rotating an array means moving the elements of each index (excluding one end ) to the following index for the right rotation and the previous index for the left rotation. For the right rotation zeroth index takes the value of the last index and vice-versa for the left rotation. Sort an array means that all the elements are in the proper increasing order. We will implement the proper code with an explanation and time, and space complexity discussion. Example Input: 5 6 9 10 2 3 3 4 Output: Yes Explanation: We can rotate the given array 4 times ... Read More

JavaScript Program to Check if it is possible to make array increasing or decreasing by rotating the array

Prabhdeep Singh
Updated on 13-Apr-2023 15:27:24

191 Views

Rotation of the array means to assume the array as a circular array and rotate the elements of the array to either their left or right direction by one index at each rotation and the element at one end may take the value present at another end. An Increasing array means that each element will be greater than or equal to its previous element and decreasing array means each element will be less than or equal to the previous element. In this problem, we are given an array and we can rotate the array in either the left or the ... Read More

JavaScript Program to Check if all rows of a matrix are circular rotations of each other

Prabhdeep Singh
Updated on 13-Apr-2023 15:26:25

233 Views

Matrix is a kind of 2-D array in which there is an array of fixed arrays that defines the rows and for each index of this array there are fixed length arrays present and the length of these arrays defines the number of columns present in the matrix. We can store any kind of data type in these cells provided by the matrix. We will be provided with a matrix and each row contains some integers and we have to check if each row is the rotation of one another or not. Rotation of each other means by some number ... Read More

JavaScript Program to Check if all array elements can be converted to pronic numbers by rotating digits

Prabhdeep Singh
Updated on 13-Apr-2023 15:25:20

119 Views

Pronic numbers are also known as rectangular numbers, the pronic numbers are numbers that are multiples of two consecutive numbers. We will be given an array of integers and we can rotate the digits in any direction for a certain number of times to get all combinations. For any combination produced by rotating the digit if each array element can be converted into the pronic number then we will print true otherwise false. Pronic Numbers First, let us discuss pronic numbers: pronic numbers are the numbers that are the product of two consecutive numbers. Mathematically saying, if we have integer ... Read More

Advertisements