JavaScript Code Daily Challenge #9

lakshyatyagi24

Lakshya Tyagi

Posted on November 30, 2020

JavaScript Code Daily Challenge #9

About

This is a series of JavaScript Code Daily Challenge. Each day I show a few solutions written in JavaScript. The questions are from coding practice/contest sites such as HackerRank, LeetCode, Codeforces, Atcoder and etc.

Minimum and Maximum
https://www.codechef.com/JULY19B/problems/MMAX/
Write Code in Comment

Subtasks

  1. Subtask #1 (30 points): 2≤N,K≤1,000
  2. Subtask #2 (70 points): original constraints

Example Input

1
3
2

Example Output

2

Explanation

Example case 1: To minimise S1, Chef could give 1 chocolate to person 1 and 1 chocolate to person 2, so S1=|1−1|+|1−0|=1.

To maximise S2, Chef can give 1 chocolate to person 1 and 1 chocolate to person 3, since the sequence B=(1,0,1) is a permutation of A=(1,1,0). Then, S2=|1−0|+|0−1|=2.

💖 💪 🙅 🚩
lakshyatyagi24
Lakshya Tyagi

Posted on November 30, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

JavaScript Code Daily Challenge #9
javascript JavaScript Code Daily Challenge #9

November 30, 2020

JavaScript Code Daily Challenge #11
javascript JavaScript Code Daily Challenge #11

December 2, 2020

JavaScript Code Daily Challenge #7
javascript JavaScript Code Daily Challenge #7

November 27, 2020

JavaScript Code Daily Challenge #6
javascript JavaScript Code Daily Challenge #6

November 26, 2020

JavaScript Code Daily Challenge #14
javascript JavaScript Code Daily Challenge #14

December 14, 2020