AmitDiwan has Published 10744 Articles

Inserting a new interval in a sorted array of intervals in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Jan-2021 04:53:57

617 Views

For the purpose of this question, we define an interval as an array of two numbers where the first number is always smaller than the second number.For example −[4, 6], [2, 3], [6, 8], [2, 7], [1, 8] are all examples of valid intervals.Suppose, we have an array of intervals ... Read More

Sorting array of exactly three unique repeating elements in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Jan-2021 04:50:46

302 Views

Suppose we have an array of Numbers that contains any frequency of exactly three elements - 1, 0 and 1 like this −const arr = [1, 1, 0, -1, 1, 0, -1, 1, 0, 0, 1];We are required to write a JavaScript function that takes in one such array. The ... Read More

Total possible ways of making sum of odd even indices elements equal in array in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Jan-2021 04:48:47

278 Views

We are required to write a JavaScript function that takes in an array of numbers as the first and the only argument.The function should then try removing one such element from the array, upon removal of which, the sum of elements at odd indices is equal to the sum of ... Read More

Convert an array of objects into plain object in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Jan-2021 04:45:35

611 Views

Suppose we have an array of objects like this −const arr = [{    name: 'Dinesh Lamba',    age: 23,    occupation: 'Web Developer', }, {    address: 'Vasant Vihar',    experience: 5,    isEmployed: true }];We are required to write a JavaScript function that takes in one such array ... Read More

Finding n subarrays with equal sum in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Jan-2021 04:43:45

134 Views

We are required to write a JavaScript function that takes in an array of integers as the first argument and an integer as the second argument.The function should check whether we can create n (second argument) subarrays from the original array such that all the subarrays have the equal sum.For ... Read More

Tribonacci series in JavaScript

AmitDiwan

AmitDiwan

Updated on 18-Jan-2021 04:40:12

1K+ Views

Tribonacci Series:The tribonacci sequence is a generalization of the Fibonacci sequence where each term is the sum of the three preceding terms.For example, the first few terms of the tribonacci series are −0, 1, 1, 2, 4, 7, 13, 24, 44, 81, 149We are required to write a JavaScript function ... Read More

Diameter of a Binary Tree in O(n) [A new method] in C++?

AmitDiwan

AmitDiwan

Updated on 16-Jan-2021 10:58:03

385 Views

The diameter of a binary tree is the (left_height + right_height + 1) for each node. So in this method we will calculate (left_height + right_height + 1) for each node and update the result . The time complexity here stays O(n).Let us first define the struct that would represent ... Read More

Diagonally Dominant Matrix in C++?

AmitDiwan

AmitDiwan

Updated on 16-Jan-2021 10:34:57

380 Views

A matrix is said to be diagonally dominant matrix if for every matrix row, the diagonal entry magnitude of the row is larger than or equal to the sum of the magnitudes of every other non-diagonal entry in that row.Let us first define a constant int variable N with value ... Read More

Diagonal Traversal of Binary Tree in C++?

AmitDiwan

AmitDiwan

Updated on 16-Jan-2021 10:28:18

248 Views

To consider the nodes that are passing between lines of slope -1. The diagonal traversal of the binary tree will be to traverse and print all those nodes present between these lines.Let us first define the struct that would represent a tree node that contains the data and its left ... Read More

Diagonal Sum of a Binary Tree in C++?

AmitDiwan

AmitDiwan

Updated on 16-Jan-2021 10:24:39

184 Views

To consider the nodes that are passing between lines of slope -1. The diagonal sum of the binary tree will be calculated by the sum of all nodes data that are present between these lines of reference.Let us first define the struct that would represent a tree node that contains ... Read More

Advertisements