Found 10710 Articles for Web Development

Length of longest string chain in JavaScript

AmitDiwan
Updated on 07-Apr-2021 08:03:09

309 Views

Word ChainLet's say word1 is a predecessor of word2 if and only if we can add exactly one letter anywhere in word1 to make it equal to word2. For example, "abc" is a predecessor of "abac".A word chain is a sequence of words [word_1, word_2, ..., word_k] with k >= 1, where word_1 is a predecessor of word_2, word_2 is a predecessor of word_3, and so on.ProblemWe are required to write a JavaScript function that takes in an array of strings, arr, as the first and the only argument.Each string in the array arr consists of English lowercase letters. Our ... Read More

Rearranging array elements in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:57:44

105 Views

ProblemJavaScript function that takes in an array of literals, arr, as the first and the only argument. This array contains some duplicates placed adjacently.Our function should rearrange the elements of the array such that no two elements in the array are equal. Our function should return the rearranged array, given that it's guaranteed that there exists at least one possible way of such arrangement.For example, if the input to the function is −const arr = [7, 7, 7, 8, 8, 8];Then the output should be −const output = [7, 8, 7, 8, 7, 8];Output Explanation:There may be other correct possible ... Read More

Two sum in BSTs in JavaScript

AmitDiwan
Updated on 07-Apr-2021 09:17:39

107 Views

Problem:We are required to write a JavaScript function that takes in the roots of two binary search trees, root1 and root2, as the first and the second argument respectively. The third argument to the function is number, target.Our function should return True if and only if there is a node in the first tree and a node in the second tree whose values sum up to a given integer target, false otherwise.For example, if the input to the function is −const target = 23;BSTsThen the output should be −const output = true;Output Explanation:Because there exists 6 in the first tree ... Read More

Distributing Bananas Problem in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:47:11

250 Views

ProblemSuppose there are n people standing in a queue, we wish to distribute bananas to the people in the following way −We give 1 banana to the first person, 2 bananas to the second person, and so on until we give n bananas to the last person.Then, we go back to the start of the row, giving n + 1 bananas to the first person, n + 2 bananas to the second person, and so on until we give 2 * n bananas to the last person.This process repeats (with us giving one more banana each time, and moving to ... Read More

Finding sequential digit numbers within a range in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:49:20

318 Views

Sequential Digits NumberA number has sequential digits if and only if each digit in the number is one more than the previous digit.ProblemWe are required to write a JavaScript function that takes in an array, arr, of exactly two elements specifying a range.Our function should return a sorted array of all the integers in the range arr (limits inclusive) that have sequential digits.For example, if the input to the function is −const arr = [1000, 13000];Then the output should be −const output = [1234, 2345, 3456, 4567, 5678, 6789, 12345];ExampleThe code for this will be − Live Democonst arr = [1000, ... Read More

JavaScript One fourth element in array

AmitDiwan
Updated on 07-Apr-2021 09:19:23

91 Views

ProblemJavaScript function that takes in an array of integers sorted in increasing order, arr.There is exactly one integer in the array that occurs more than one fourth times (25%) of the times, our function should return that number.For example, if the input to the function is −const arr = [3, 5, 5, 7, 7, 7, 7, 8, 9];Then the output should be −const output = 7;Example Live DemoThe code for this will be −const arr = [3, 5, 5, 7, 7, 7, 7, 8, 9]; const oneFourthElement = (arr = []) => {    const len = arr.length / 4;    const search = (left, right, target, direction = 'left') => {       let index = -1       while (left

Removing already listed intervals in JavaScript

AmitDiwan
Updated on 07-Apr-2021 09:20:49

115 Views

ProblemJavaScript function that takes in a 2-D array, arr, as the first and the only argument.Each subarray of our input array is an array of exactly two numbers, specifying a time interval.Our function should remove all intervals that are covered by another interval in the array arr. Interval [a,b) is covered by interval [c,d) if and only if c (a === c ? d - b : a - c));    let last = arr[0];    let count = arr.length;    for(let i = 1; i < arr.length; i++){       const [a, b] = last;       const [c, d] = arr[i];       if(c >= a && d

Path with smallest sum in JavaScript

AmitDiwan
Updated on 07-Apr-2021 07:26:18

207 Views

ProblemJavaScript function that takes in a 2-D array of numbers as the first and the only argument.Our function should find paths from the 2-D array by picking exactly one element from each row, and no two elements picked from adjacent rows should be in the same column. Out of all these paths, our function should return the sum of that path that has the minimum sum.For example, if the input to the function is −const arr = [    [4, 7, 1],    [2, 8, 3],    [5, 6, 9] ]Then the output should be −const output = 9;Output ExplanationBecause ... Read More

Difference Between GET and POST Method in HTML

AmitDiwan
Updated on 23-Mar-2021 07:30:17

4K+ Views

In this post, we will understand the difference between GET and POST methods in HTML.GET MethodThe parameters are placed inside the URL.Its main goal is to retrieve the data/documents present inside it.It has the ability to bookmark the results of the query.It is vulnerable, and not secure enough.This is because the data and credentials are present as plain text.It can be seen by anyone.The data constraint is that only ASCII characters are allowed.It can be up to 2000 characters only.It is also said to keep the length of the data to a minimum value.Data can be cached when GET method ... Read More

Difference Between Cellpadding and Cellspacing

Kiran Kumar Panigrahi
Updated on 20-Dec-2022 12:17:13

6K+ Views

In HTML, cellpadding and cellspacing are the two attributes used for formatting table cells. Both cellpadding and cellspacing are used to insert whitespaces in the table cells. The most basic difference between cellpadding and cellspacing is that the cellpadding is used to set the whitespace between cell edge and cell content, whereas cellspacing is used to set the whitespace between two cells.Read through this article to find out more about cellpadding and cellspacing and how they are different from each other. What is Cellpadding? In HTML table formatting, cellpadding is the attribute which is used to set the whitespace between ... Read More

Advertisements