Found 8895 Articles for Front End Technology

JavaScript Program to Check if strings are rotations of each other or not

Prabhdeep Singh
Updated on 04-May-2023 11:00:13

373 Views

Strings are rotations of each other means two strings that 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. We will be given two strings and we have to find whether by rotating the characters of the string we can get another or not. Input string1: “abcdef” string2: ... Read More

JavaScript Program to Check if Matrix is Upper Triangular

Prabhdeep Singh
Updated on 13-Apr-2023 15:31:41

94 Views

An Upper triangular matrix is a squared matrix that has the same number of rows and columns and all the elements that are present below the main diagonal passing from the first cell (present at the top-left) towards the last cell (present at the bottom-right) are zero. Upper triangular means the elements present in the lower triangle will be zero. We will implement a proper code with explanation and discussion over time and space complexity. Example Input1: mat = [ [ 1, 2, 3, 4], [ 0, 5, 6, 7], [ 0, 0, 8, ... Read More

JavaScript Program to check if the matrix is lower Triangular

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

67 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

57 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

87 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

125 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

59 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

JavaScript Program to Check if a string can be formed from another string by at most X circular clockwise shifts

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

104 Views

Circular clockwise shifts for the string mean rotating the characters of the string to their next character in alphabetic order. For each circular shift characters are converted to the next character and if there is no character present after the certain rotations (as ‘z’ is the last character of the English alphabet), then for that case we can assume characters in the cycle, and again start from the first character of English alphabets. We will be given two strings and we can rotate each character of the first string maximum of x numbers of times, and after doing a certain ... Read More

JavaScript Program for Rotate Doubly linked list by N nodes

Prabhdeep Singh
Updated on 13-Apr-2023 15:21:21

157 Views

A doubly linked list is a linear data structure where each node stores the address of the next and previous node. We have given a doubly linked list and we have to rotate the doubly linked list by N nodes and print it. Here N is the positive number and less than or equal to the count of the nodes present in the linked list. We are not given the specific side to rotate the doubly linked list. So we will rotate the doubly linked list in both ways. Rotating Doubly Linked List to Counter Clockwise We have to rotate ... Read More

JavaScript Program to Check if a string can be obtained by rotating another string by 2 places

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

155 Views

We have given two strings s1 and s2 and we have to check if is it possible to obtain a string by rotating another string by 2 places. We can rotate the string either in an anti-clockwise or clockwise direction. Here we have to print ‘Yes’ if both the string got match after the rotation of the string by 2 places otherwise, we have to print ‘No’. Examples Let us assume we have given two strings s1 and s2 as Example 1 Input: s1 = “TutorialsPoint”, s2 = “PointTutorials” Output: No Explanation: here s2 is the anti-clockwise rotation of ... Read More

Advertisements