JavaScript Program for Mirror of Matrix Across Diagonal

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

419 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

JavaScript Program to Find Lexicographically minimum string rotation

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

612 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

JavaScript program to convert 24 hours format to 12 hours

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

JavaScript Program for Rotate a Matrix by 180 degrees

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

370 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

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

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

425 Views

Counting sets of 1s and 0s in a binary matrix can be achieved using nested for loop with conditional statement. 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 are having a 2D binary matrix having 0 and 1 only. Our task is to write a JavaScript program for counting the sets of 1s and 0s in a given binary matrix. Formula: Let us a consider a set as {a, b} having 2 elements i.e, n = 2. Total number ... Read More

JavaScript Program for Maximum and Minimum in a Square Matrix

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

315 Views

To get maximum and minimum in a Square Matrix in JavaScript, we will be discussing two different approaches, their complexities, and example codes. First approach make use of nested loop while second approach uses Math function. In this article we are having a 2D square matrix, our task is to write a JavaScript program for maximum and minimum in a square matrix. Example Input: Matrix: [ [1, 3, 7], [5, 2, 9], [2, 5, 1] ] Output: Maximum = 9, Minimum = 1 ... Read More

JavaScript Program for Frequencies of Even and Odd Numbers in a Matrix

Ravi Ranjan
Updated on 06-Jun-2025 19:11:52

265 Views

To get frequencies of even and odd numbers in a matrix, we will be discussing three different approaches. We will discuss each approach with code examples and solution of the algorithm being used. In this article we are having a 2D matrix, our task is to write a JavaScript program for frequencies of even and odd numbers in a matrix. Users must be familiar with conditional statement, nested loops and javascript operators. Example Input: Matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; Even numbers: {2, 4, 6, 8} Odd numbers: {1, 3, 5, 7, ... Read More

JavaScript Program to Efficiently Compute Sums of Diagonals of a Matrix

Ravi Ranjan
Updated on 06-Jun-2025 19:11:29

422 Views

To efficiently compute sums of diagonals of a matrix, we will be discussing two different approaches. We will calculate the sum of the elements present in the left-to-right and right-to-left diagonal i.e primary and secondary diagonal respectively. In this article we are having a square matrix, our task is to write a JavaScript program to efficiently compute sums of diagonals of a matrix. Example Input: Matrix: [[1, 2, 3], [4, 5, 6], [9, 8, 9]] Sum of primary diagonal elements = 1+5+9 Sum of secondary diagonal elements = 3+5+9 Output: Sum of ... Read More

JavaScript Program for Diagonally Dominant Matrix

Ravi Ranjan
Updated on 06-Jun-2025 19:11:07

242 Views

Diagonally dominant matrix refers to square matrix having magnitude of diagonal element in a row greater than or equal to the sum of magnitude of non-diagonal elements in that row. In this article we are having a square matrix, our task is to write JavaScript program for diagonally dominant matrix. Users must be familiar with 2D matrix, nested for loop and conditional statement. Formula: $$\mathrm{|\:a_{ii}\:|\:\geq\:\displaystyle\sum\limits_{j ≠ i}\:|\:a_{ij}|}$$ for all i Where aij denotes the entry in the ith row and jth column Example Input: [A] = ... Read More

What do single quotes do in C++ when used on multiple characters?

Farhan Muhamed
Updated on 06-Jun-2025 18:59:11

961 Views

Single quotes in C++ are used to denote characters, not strings. When you use single quotes around multiple characters or strings, C++ compiler will treat it as a multi-character literal, which will be stored as an integer value, representing the combined ASCII values of those characters. In this article, we will learn all about single quotes in C++ and how they behave when used with multiple characters. Single Quotes in C++ In C++, single quotes are used to represent a single character. For example, 'a' is a character literal representing the english alphabet 'a'. For each character, C++ assigns a ... Read More

Advertisements