Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Prabhdeep Singh
161 articles
JavaScript Program to Check if a string can be obtained by rotating another string d places
Rotating a string means moving characters to the left or right by a specified number of positions. We'll check if one string can be obtained by rotating another string exactly d places in either direction. Problem Understanding Given two strings and a rotation count d, we need to determine if the first string can be transformed into the second string by rotating it d positions left or right. Example String 1: "abcdef", String 2: "defabc", Rotations: 3 Left rotation by 3: "abcdef" → "bcdefa" → "cdefab" → "defabc" ✓ Approach 1: Left Rotation ...
Read MoreJavaScript Program for Rotate Doubly linked list by N nodes
A doubly linked list is a linear data structure where each node stores references to both the next and previous nodes. In this tutorial, we'll learn how to rotate a doubly linked list by N nodes in both clockwise and counter-clockwise directions. Rotation means moving elements from one end of the list to the other. For N rotations, we take N nodes from one end and move them to the opposite end while maintaining the doubly linked structure. Understanding Rotation Direction Counter-clockwise rotation: Move the first N nodes to the end of the list. Clockwise rotation: Move ...
Read MoreJavaScript Program to Check if all array elements can be converted to pronic numbers by rotating digits
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. What are Pronic Numbers? First, let us discuss pronic numbers: pronic numbers are the numbers that are the product of two consecutive numbers. Mathematically saying, if ...
Read MoreJavaScript Program to Check if all rows of a matrix are circular rotations of each other
A matrix in JavaScript is a 2-dimensional array where each row contains a fixed number of elements. In this tutorial, we'll learn how to check if all rows of a matrix are circular rotations of each other, meaning we can transform any row into another through left or right rotations. Circular rotation means shifting elements: rotating [1, 2, 3] right gives [3, 1, 2], and rotating left gives [2, 3, 1]. Problem Understanding Given a matrix, we need to determine if every row can be converted to the first row through circular rotations. Example 1 ...
Read MoreJavaScript Program for Clockwise rotation of Linked List
In JavaScript, a clockwise rotation of a linked list moves the last k elements to the front. This operation is commonly used in data structure manipulations and algorithm problems. Given a linked list and a rotation count k, we need to move the last k nodes to the beginning. For example, rotating 1 → 2 → 3 → 4 → 5 clockwise by 2 positions results in 4 → 5 → 1 → 2 → 3. Structure of Linked List First, we'll create a Node class and helper functions to build and display the linked list: ...
Read MoreJavascript Program for Range Queries for Frequencies of array elements
We are given an array that will contain integers and another array will be given that will contain the queries and each query represents the range that we are given by the leftmost and the rightmost index in the array and an element. For that range or the subarray, we have to find the frequency of the given element present in that range. The frequency of the elements means that we have to tell for each integer present in that range how many times it occurs. For example − If, the given array is: [5, 2, 5, 3, ...
Read MoreJavaScript Program for Removing Duplicates From An Unsorted Linked List
The linked list is a linear data structure that consists of nodes, and each node is stored in memory in a non-contiguous manner. Nodes are connected by storing the address of the next node. We are given a linked list that will contain some integers in a random manner and not in a sorted manner. The task is to find the elements of the linked list which are repeated and we have to remove the duplicated ones. In this problem, we will keep the first copy of the elements of the linked list and remove the elements which are ...
Read MoreJavaScript Program to Check if it is possible to make array increasing or decreasing by rotating the array
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 ...
Read MoreJavaScript Program for Reversal algorithm for array rotation
An array is a linear data structure used to store different types of objects. Given an array of size n and an integer k, we need to rotate the array by k elements to the left and return the rotated array. Rotation means shifting all elements to the left by k positions. Elements that move beyond the first position wrap around to the end of the array. Note − During rotation, when elements shift left, those at the beginning move to the end, creating a circular shift pattern. Let us see an example − Input: ...
Read MoreJavaScript Program for Reversal algorithm for right rotation of an array
Right rotation of an array means shifting elements to the right by a given number of positions. Elements that move beyond the array's end wrap around to the beginning. We'll implement the reversal algorithm, which is an efficient approach for array rotation. Example Input array: [1, 2, 3, 4, 5, 6, 7, 8, 9] Right rotations: 3 Output: [7, 8, 9, 1, 2, 3, 4, 5, 6] How Right Rotation Works Let's trace through 3 right rotations step by step: Original: [1, 2, 3, 4, 5, 6, 7, 8, 9] After 1st ...
Read More