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
Page 3 of 17
JavaScript Program to Check whether all the rotations of a given number are greater than or equal to the given number or not
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 ...
Read MoreJavaScript Program for Count Primes in Ranges
Prime numbers are numbers that have exactly two perfect divisors (1 and themselves). This article explores multiple methods to count prime numbers in a given range using JavaScript. We'll start with basic approaches and then optimize using the Sieve of Eratosthenes algorithm for better performance. Method 1: Direct Approach (O(N) per number) This method counts all divisors of a number. If exactly 2 divisors exist, the number is prime. function isPrime(number) { var count = 0; for (var i = 1; i
Read MoreJavaScript Program to Find Minimum Insertions to Form a Palindrome
We are given a string and we have to find the minimum number of characters that we need to insert at any position to make the string a palindrome. A palindrome is a string that reads the same forwards and backwards. This problem can be solved using dynamic programming - we'll explore three approaches: recursive, memoization, and tabulation. Understanding the Problem For example, to make "abc" a palindrome, we need to insert 2 characters to get "abcba" or "cbabc". The key insight is that if characters at both ends match, we can focus on the substring between them. ...
Read MoreJavaScript Program for Writing A Function To Get Nth Node In A Linked List
Linked list is a linear data structure where nodes are connected by storing the address of the next node. Finding the nth node means retrieving the value at the nth position in the linked list, which can be accomplished using iterative or recursive methods. Problem Example Given linked list: 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> null Node to find: 3rd position Output: 3 Explanation: The value at the 3rd position is 3. Using Iterative Approach This approach traverses the linked list using a ...
Read MoreJavaScript Program for Finding a Triplet from Three Linked Lists with a Sum Equal to a Given Number
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 variation of the standard three-sum problem but applied to linked lists instead of arrays. Problem Statement Given three linked lists and a target number, we need to find if there exists a triplet (one element from each list) whose sum equals the target number. If such a triplet exists, return true; otherwise, return false. Example: Target: 10 List 1: 1 → 2 → 3 ...
Read MoreJavaScript Program To Add Two Numbers Represented By Linked Lists- Set 1
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. Problem Statement Given two linked lists where each node contains a single digit, we need to add the numbers they ...
Read MoreJavaScript Program for Finding Length of a Linked List
To find the length of a linked list in JavaScript, we need to count how many nodes are present. A linked list is made up of nodes, where each node contains data and a reference to the next node. The length is determined by starting at the head and counting each node until the end of the list. If the list is empty, the length should be 0. Our task is to write a JavaScript program that calculates the length of a linked list. In other words, we need to find out how many nodes are in the list. ...
Read MoreJavaScript Program to Find Longest Common Prefix Using Word by Word Matching
Prefixes are substrings that start from the zeroth index of a string and can be of any size from 1 to the complete length of the string. We are given a set of strings and need to find the longest common prefix among all of them using JavaScript. We'll implement word-by-word matching approach where we compare characters at the same position across all strings. Input arr = ["zefkefgh", "zefkdefij", "zeffdzy", "zefkdabacd"]; Output zef Explanation From all the given strings, the first three ...
Read MoreJavaScript Program for Inserting a Node in a Linked List
A linked list is a linear data structure where elements (nodes) are stored in sequence, with each node containing data and a reference to the next node. Unlike arrays, linked lists allow efficient insertion and deletion at any position without shifting elements. In this article, we'll explore how to insert nodes into a linked list using JavaScript, covering insertion at the beginning, specific positions, and the end of the list. Basic Node Structure First, let's define a simple Node class that represents each element in our linked list: class Node { ...
Read MoreJavaScript Program for Finding Intersection Point of Two Linked Lists
In this tutorial, we will discuss two approaches to finding the intersection point of two linked lists in JavaScript. The first approach uses nested loops, and the second approach uses the difference of nodes technique which works in linear time. We will be given two linked lists that may intersect at some point. The intersection point is where both lists share the same node reference (not just the same value). After the intersection point, all subsequent nodes are identical in both lists. Problem Statement Given two linked lists, we need to find the node where they intersect. ...
Read More