Calculate the height of binary tree
var maxDepth = function(root) {
if (root === null) return 0
return Math.max(maxDepth(root.left), maxDepth(root.right)) + 1
};

Input : arr[] = [1, 2, 3, 0, -1, 8, 10]
Output : 21
10 + 8 + 3 = 21

Approach,

we simply run three-loop and one by one add three-element and compare with the previous sum if the sum of three-element is greater than store in the previous sum.

function maxTripletSum(arr, n) {    // sort the given array    arr.sort();
// Add last three element of the given array return arr[n - 1] + arr[n - 2] + arr[n - 3];}// input let arr = [ 1, 0, 8, 6, 4, 2 ];let n = arr.length;maxTripletSum(arr, n);// output - 18

Input
["LRUCache", "put", "put", "get", "put", "get", "put", "get", "get", "get"]
[[2], [1, 1], [2, 2], [1], [3, 3], [2], [4, 4], [1], [3], [4]]
Output
[null, null, null, 1, null, -1, null, -1, 3, 4]

Explanation
LRUCache lRUCache = new LRUCache(2);
lRUCache.put(1, 1)…

iAmSonika | www.startlearncoding.com

Working in Walmart as UI Developer | Mentor | React | JavaScript | HTML | CSS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store