AmitDiwan has Published 10744 Articles

Checking validity of equations in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:37:05

275 Views

ProblemWe are required to write a JavaScript function that takes in an array, arr, as the first and the only argument.The array arr consists of string equations of one of the two following kinds −‘X ===Y’X!==Y’Here, X and Y can be any variables.Our function is supposed to check whether for ... Read More

Finding squares in sorted order in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:29:31

244 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, sorted in increasing order.Our function is supposed to return an array of the squares of each number, also sorted in increasing order.For example, if the input to the function is −const arr = [-2, ... Read More

Sum which is divisible by n in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:26:33

225 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first argument, and a number, num, as the second argument. Our function should return the number of (contiguous, non-empty) subarrays that have a sum divisible by num.For example, if the input to ... Read More

Finding points nearest to origin in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:25:12

648 Views

ProblemWe are required to write a JavaScript function that takes in an array of coordinates, arr, as the first argument, and a number, num, as the second argument.Our function should find and return the num closest points to the origin (0, 0).(Here, the distance between two points on a plane ... Read More

Checking for univalued Binary Search Tree in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:22:00

130 Views

Univalued Binary Search TreeA binary search tree is univalued if every node in the tree has the same value.ProblemWe are required to write a JavaScript function that takes in the root of a BST and returns true if and only if the given tree is univalued, false otherwise.For example, if ... Read More

Index difference of tuples in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:19:35

149 Views

ProblemWe are required to write a JavaScript function that takes in an array of integers, arr, as the first and the only argument.Suppose two indices, i and j in the array which satisfy the following conditions −i < j, andarr[i] {    let max = 0    const stack ... Read More

Rearranging elements of an array in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:18:11

277 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, will always be of even length.Our function should return true if and only if it is possible to reorder it such that arr[2 * i ... Read More

Validating push pop sequence in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:15:43

382 Views

ProblemJavaScript function that takes in two arrays, pushed and popped, as the first and the second argument. Both these arrays are guaranteed to consist of unique elements.Our function should return true if and only if this could have been the result of a sequence of push and pop operations on ... Read More

Making array unique in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:11:08

243 Views

ProblemWe are required to write a JavaScript function that takes in an array of numbers, arr, as the first and the only argument.A move consists of choosing any arr[i], and incrementing it by 1. Our function is supposed to return the least number of moves to make every value in ... Read More

Checking for centrally peaked arrays in JavaScript

AmitDiwan

AmitDiwan

Updated on 09-Apr-2021 09:09:37

106 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 check whether the input array is a centrally peaked array or not. If it is a centrally peaked array, we should return true, false otherwise.The ... Read More

Advertisements