AmitDiwan has Published 10744 Articles

Removing already listed intervals in JavaScript

AmitDiwan

AmitDiwan

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

150 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) ... Read More

JavaScript One fourth element in array

AmitDiwan

AmitDiwan

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

133 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, ... Read More

Two sum in BSTs in JavaScript

AmitDiwan

AmitDiwan

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

191 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 ... Read More

Removing adjacent duplicates from a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 07-Apr-2021 09:08:45

2K+ Views

ProblemJavaScript function that takes in a string, str, as the first and the only argument.A duplicate removal consists of choosing two adjacent and equal letters, and removing them.We repeatedly make duplicate removals on string str until we no longer can.And our function should finally return the final string after all ... Read More

Finding next greater node for each node in JavaScript

AmitDiwan

AmitDiwan

Updated on 07-Apr-2021 09:06:32

196 Views

ProblemWe are required to write a JavaScript function that takes in the head of the linked list as the first and the only argument.This linkedlist contains numerical data. Each node in the list may have a next larger value: for node_i, next_larger(node_i) is the node_j.val such that j > i, ... Read More

Greatest sum and smallest index difference in JavaScript

AmitDiwan

AmitDiwan

Updated on 07-Apr-2021 09:04:10

126 Views

ProblemJavaScript function that takes in an array of Integers, arr, as the first and the only argument.Our function should pick an index pair (i, j) such that (arr[i] + arr[j]) + (i - j) is maximum amongst all index pairs in the array. Our function should then return the maximum ... Read More

Length of longest string chain in JavaScript

AmitDiwan

AmitDiwan

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

367 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 >= ... Read More

Rearranging array elements in JavaScript

AmitDiwan

AmitDiwan

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

187 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 ... Read More

Finding sequential digit numbers within a range in JavaScript

AmitDiwan

AmitDiwan

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

397 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 ... Read More

Distributing Bananas Problem in JavaScript

AmitDiwan

AmitDiwan

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

344 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 ... Read More

Advertisements