AmitDiwan has Published 10744 Articles

Sorting array based on increasing frequency of elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:20:08

254 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.The array arr, might contain some duplicates. Our function is supposed to sort the array in such a way that the elements that appear for least number of ... Read More

Minimum deletion sum of characters in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:19:34

126 Views

ProblemWe are required to write a JavaScript function that takes in two strings of English lowercase alphabets, str1 and str2, as the first and the second argument respectively.Our function is supposed to find and return the lowest ASCII sum of deleted characters to make two strings equal.For example, if the ... Read More

Product of subarray just less than target in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:19:09

150 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument, and a number, target, as the second argument.Our function is supposed to count and return the number of (contiguous) subarrays where the product of all the elements in the subarray ... Read More

Finding maximum length of common subarray in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:15:35

348 Views

ProblemWe are required to write a JavaScript function that takes in two arrays of literals, arr1 and arr2, as the first and the second argument respectively.Our function is supposed to return the maximum length of a subarray that appears in both arrays.For example, if the input to the function isInputconst ... Read More

Finding state after all collisions in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:14:27

135 Views

ProblemWe are required to write a JavaScript function that takes in an array, arr, that represents the positions of different asteroids in a one-dimensional space.For each asteroid, the absolute value represents its size, and the sign represents its direction (positive meaning right, negative meaning left). Each asteroid moves at the ... Read More

Just smaller number with monotone digits in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:13:41

145 Views

Monotonically Increasing DigitsAn integer has monotone increasing digits if and only if each pair of adjacent digits x and y satisfy x {    const checkMonotone = (x) =>{       if (x = nextDigit) {             currentDigit = nextDigit       ... Read More

Finding distance to next greater element in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:12:46

247 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.Our function should construct a new array for the input in which each corresponding element is the distance to the next greater element than the current element, and ... Read More

Convert mixed case string to lower case in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:09:19

379 Views

ProblemWe are required to write a JavaScript function convertToLower() that takes in a string method that converts the string it is being called upon into lowercase string and returns the new string.For example, if the input to the function isInputconst str = 'ABcD123';Outputconst output = 'abcd123';ExampleFollowing is the code − Live ... Read More

Splitting a string into maximum parts in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:03:43

314 Views

ProblemWe are required to write a JavaScript function that takes in a string, str, as the first and the only argument.The purpose of our function is to partition this string into as many parts as possible so that each letter appears in at most one part, and return an array ... Read More

Checking for particular types of matrix in JavaScript

AmitDiwan

AmitDiwan

Updated on 24-Apr-2021 10:02:55

79 Views

ProblemWe are required to write a JavaScript function that takes in a 2-D array of literals, arr, as the first and the only argument.Our function should check if every diagonal from top-left to bottom-right has the same element.If it is so, we should return true, false otherwise.For example, if the ... Read More

Advertisements