JavaScript | Array | Maximum triplet sum in Array (easy)

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

Approach,

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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Pseudo-random Beasts and Where to Find Them: A Cheat Sheet for ES6 & Python 3

Leetcode — 127. Word Ladder

Install Tailwind CSS with Next.Js In 5 Steps!

What is Node JS?

Node.js Basic Concept

Express React

Angular 13 tutorial: Build a web app by example with Bootstrap 4

The importance of using Server-Side Rendering with Next.JS

Next.JS with Server-Side Rendering. Showing a server with an arrow pointing to a laptop

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
iAmSonika | www.startlearncoding.com

iAmSonika | www.startlearncoding.com

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

More from Medium

Frequency Counter — JavaScript

Write a program to sort the given array — JAVASCRIPT

Temporal Dead Zone

Temporal Dead Zone

Javascript Concepts