• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Jun 18th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function solve(input) {
2.     let n = Number(input.shift());
3.
4.     let maxNum = Number.MIN_SAFE_INTEGER;
5.     let minNum = Number.MAX_SAFE_INTEGER;
6.     let value = 0;
7.     let lastPair = 0;
8.     let currentPair = 0;
9.     let maxNumDiff = 0;
10.
11.     for (let i = 1; i <= n; i++) {
12.         let num1 = Number(input.shift());
13.         let num2 = Number(input.shift());
14.
15.         if (i > 1) {
16.             lastPair = num1 + num2;
17.
18.             if (currentPair === lastPair) {
19.                 value = currentPair;
20.             }
21.             else {
22.                 if (currentPair > maxNum) {
23.                     maxNum = currentPair;
24.                 }
25.                 if (lastPair > maxNum) {
26.                     maxNum = lastPair;
27.                 }
28.                 if (currentPair < minNum) {
29.                     minNum = currentPair;
30.                 }
31.                 if (lastPair < minNum) {
32.                     minNum = lastPair;
33.                 }
34.                 maxNumDiff = maxNum - minNum;
35.             }
36.
37.         }
38.         else {
39.             currentPair = num1 + num2;
40.
41.             if (n <= 1) {
42.                 value = num1 + num2;
43.                 lastPair = currentPair;
44.             }
45.         }
46.
47.     }
48.
49.     if (currentPair === lastPair) {
50.         console.log(`Yes, value=\${value}`)
51.     }
52.     else if (currentPair != lastPair){
53.         console.log(`No, maxdiff=\${maxNumDiff}`)
54.     }
55.
56. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top