JavaScript Code Daily Challenge #9
Lakshya Tyagi
Posted on November 30, 2020
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
- Subtask #1 (30 points): 2≤N,K≤1,000
- 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.
💖 💪 🙅 🚩
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.