We need to find two strings from an array that share no common characters and have the maximum product of their lengths. This problem efficiently uses bitwise operations to represent character sets. Problem Statement Given an array of lowercase strings, find two strings with no common characters that have the maximum length product. Return 0 if no such pair exists. For example: const arr = ["karl", "n", "the", "car", "mint", "alpha"]; // Expected output: 20 (mint: 4 chars × alpha: 5 chars = 20) How It Works The solution uses bit manipulation ... Read More
The document.getElementById() method allows us to access any HTML element using its id in JavaScript. Every webpage can contain only a single HTML element with a single id. You can use the below example code to access any HTML element using its id: let element = document.getElementById('id'); In the above code, we used the getElementById() method of the document object and passed the id as a parameter. Now, if we require to access multiple elements using their id, it is not a good idea to repeatedly type document.getElementById(), but we can create a ... Read More
In JavaScript, you can remove elements from JSON objects or arrays using different methods. This article demonstrates how to remove properties from JSON objects and elements from JSON arrays. Sample JSON Data Let's work with the following JSON array containing customer information: var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", ... Read More
When working with strings that contain capitalized words, you might need to insert a character (like a comma) before each capital letter. This is useful for parsing concatenated sentences or formatting text data. Problem Statement Given a string with capitalized words, we want to add a comma before each capital letter that appears after another character: const str = "Connecting to server Connection has been successful We found result"; The goal is to transform this into: "Connecting to server, Connection has been successful, We found result" Solution Using Regular Expression We can ... Read More
We have two arrays of numbers and need to find elements that exist in one array but not in both. This is called finding the symmetric difference or deviation between arrays. const arr1 = [12, 54, 2, 4, 6, 34, 3]; const arr2 = [54, 2, 5, 12, 4, 1, 3, 34]; We need to write a JavaScript function that takes two arrays and returns elements that are not common to both arrays. Using indexOf() Method The basic approach uses indexOf() to check if elements exist in the other array: const arr1 ... Read More
ES6 allows you to set default parameters for nested objects using destructuring assignment. This feature helps handle cases where nested properties might be undefined or missing. Syntax function myFunction({ outerKey: { innerProperty = defaultValue, anotherProperty = anotherDefault } = {} } = {}) { // Function body } Example Here's how to implement default parameters in nested objects: function ... Read More
A beautiful arrangement is a permutation of numbers from 1 to num where each position satisfies specific divisibility rules. This problem involves finding all valid arrangements using backtracking. Definition For an array with num integers from 1 to num, a beautiful arrangement requires that for each position i (1-indexed): The number at position i is divisible by i, OR i is divisible by the number at position i Problem Statement Write a JavaScript function that takes a number and returns the count of all possible ... Read More
In JavaScript, removing duplicate characters while maintaining lexicographical order requires a strategic approach. This problem asks us to keep only one occurrence of each character, choosing positions that result in the lexicographically smallest string. Problem Statement We need to write a JavaScript function that takes a string and returns a new string where each character appears only once. The key constraint is that the result must be lexicographically smallest among all possible combinations. For example, with input 'cbacdcbc', the output should be 'acdb'. Understanding the Algorithm The solution uses a greedy approach: ... Read More
Before creating the project, we will first discuss REST API. REST is a software architecture style and a collection of standards that helps make online services. Representational State Transfer is the full name of REST. Application programming interfaces (API) allow communication between two or more computer programmes. It is a software interface that gives other software programmes a service. The user must follow the rules known as a REST API based on the HTTP (Hypertext Transfer Protocol) to access web services. Conventional HTTP methods like GET, POST, PUT, and DELETE access and modify resources like data objects in a ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Economics & Finance