AmitDiwan has Published 10744 Articles

Checking if a number is a valid power of 4 in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Mar-2021 05:54:14

352 Views

ProblemWe are required to write a JavaScript function that takes in a single integer, num, as the only argument. Our function should check whether this number is a valid power of 4 or not. If it is a power of 4, we should return true, false otherwise.For example, if the ... Read More

Breaking integer to maximize product in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Mar-2021 05:51:28

133 Views

ProblemWe are required to write a JavaScript function that takes in an Integer, num, as the first and the only argument.Our function should break these integers into at least two chunks which when added gives the sum integer num and when multiplied gives maximum possible product. Finally, our function should ... Read More

Reversing consonants only from a string in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Mar-2021 05:48:09

389 Views

ProblemWe are required to write a JavaScript function that takes in a string of lowercase english alphabets as the only argument.The function should construct a new string in which the order of consonants is reversed and the vowels hold their relative positions.For example, if the input to the function is ... Read More

Finding array intersection and including repeating elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 19-Mar-2021 05:45:33

1K+ Views

ProblemWe are required to write a JavaScript function that takes in two arrays, arr1 and arr2 as first and second arguments respectively.The function should find the intersection (common elements between both) of the arrays and if there are elements that appear twice in both the arrays, we should include them ... Read More

Is the string a combination of repeated substrings in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Mar-2021 13:51:18

297 Views

ProblemWe are required to write a JavaScript function that takes in a string of characters as the only argument. Our function needs to check if the string str can be constructed by taking a substring of it and appending multiple copies of the substring together.For example, if the input to ... Read More

Sorting string characters by frequency in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Mar-2021 13:49:54

812 Views

ProblemWe are required to write a JavaScript function that takes in the string of characters as the only argument.Our function should prepare and a new string based on the original string in which the characters that appear for most number of times are placed first followed by number with decreasing ... Read More

Finding Sum of Left Leaves of a BST in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Mar-2021 13:45:48

341 Views

ProblemWe are required to write a JavaScript function that takes in the root of a Binary Search Tree as the only argument.The function should simply calculate the sum of data stored in the left leaves of the BST.For example, if the Tree looks like this −8 / \ 1 10 ... Read More

Smallest number after removing n digits in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Mar-2021 13:43:19

305 Views

ProblemWe are required to write a JavaScript function that takes in two numbers, let’s call them m and n as first and the second argument respectively.The task of our function is to remove n digits from the number m so that the number m is the smallest possible number after ... Read More

Bring number down to 1 in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Mar-2021 13:40:00

93 Views

ProblemWe are required to write a JavaScript function that takes in number, num as the only argument.Our function can do only these two operations on num: If num is even, we can replace num with num/2If num is odd, we can replace num with either num + 1 or num ... Read More

Nth smallest element in sorted 2-D array in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Mar-2021 13:37:47

370 Views

ProblemSuppose, we have a sorted array of arrays of Numbers (sorted in increasing order) like this −const arr = [    [ 1, 5, 9],    [10, 11, 13],    [12, 13, 15] ];We are required to write a JavaScript function that takes in in one such array as the ... Read More

Advertisements