kandi background
Explore Kits

leetcode | LeetCode Solutions : A Record of My Problem Solving Journey | Learning library

 by   azl397985856 JavaScript Version: v0.38 License: Non-SPDX

 by   azl397985856 JavaScript Version: v0.38 License: Non-SPDX

kandi X-RAY | leetcode Summary

leetcode is a JavaScript library typically used in Tutorial, Learning, Example Codes, LeetCode applications. leetcode has no bugs, it has no vulnerabilities and it has medium support. However leetcode has a Non-SPDX License. You can download it from GitHub.
我们的 slogon 是: 只有熟练掌握基础的数据结构与算法,才能对复杂问题迎刃有余。.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • leetcode has a medium active ecosystem.
  • It has 43986 star(s) with 8299 fork(s). There are 1364 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 8 open issues and 221 have been closed. On average issues are closed in 82 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of leetcode is v0.38
leetcode Support
Best in #Learning
Average in #Learning
leetcode Support
Best in #Learning
Average in #Learning

quality kandi Quality

  • leetcode has 0 bugs and 0 code smells.
leetcode Quality
Best in #Learning
Average in #Learning
leetcode Quality
Best in #Learning
Average in #Learning

securitySecurity

  • leetcode has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • leetcode code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
leetcode Security
Best in #Learning
Average in #Learning
leetcode Security
Best in #Learning
Average in #Learning

license License

  • leetcode has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
leetcode License
Best in #Learning
Average in #Learning
leetcode License
Best in #Learning
Average in #Learning

buildReuse

  • leetcode releases are available to install and integrate.
  • leetcode saves you 14 person hours of effort in developing the same functionality from scratch.
  • It has 32 lines of code, 1 functions and 20 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
leetcode Reuse
Best in #Learning
Average in #Learning
leetcode Reuse
Best in #Learning
Average in #Learning
Top functions reviewed by kandi - BETA

kandi has reviewed leetcode and discovered the below as its top functions. This is intended to give you an instant insight into leetcode implemented functionality, and help decide if they suit your requirements.

  • Backtrack the given list
    • Computes the number of the left right .
      • Counts gaps .
        • Find the k . k . ks and b .
          • Checks if a given character is in Polygon .
            • Determines if a prefix is a prefix of a string .
              • Proofs where we are going to the board .
                • Preorder the tree .
                  • Helper function for calculating the index of the index .

                    Get all kandi verified functions for this library.

                    Get all kandi verified functions for this library.

                    leetcode Key Features

                    LeetCode Solutions: A Record of My Problem Solving Journey.( leetcode题解,记录自己的leetcode解题之路。)

                    leetcode Examples and Code Snippets

                    See all related Code Snippets

                    Using while let with two variables simultaneously

                    copy iconCopydownload iconDownload
                    while let Some((n1, n2)) = node1.zip(node2) {
                        ...
                    }
                    
                    #![feature(let_chains)]
                    
                    while let Some(n1) = node1 && let Some(n2) = node2 {
                        // ...
                    }
                    

                    Is this Union Find really O(n) as they claim?

                    copy iconCopydownload iconDownload
                    return parent[i]=find(parent[i])
                    
                    return find(parent[i])
                    
                    if(sz[p1]>sz[p2]) {...
                    
                    return parent[i]=find(parent[i])
                    
                    return find(parent[i])
                    
                    if(sz[p1]>sz[p2]) {...
                    
                    return parent[i]=find(parent[i])
                    
                    return find(parent[i])
                    
                    if(sz[p1]>sz[p2]) {...
                    

                    How are javascript variables referenced?

                    copy iconCopydownload iconDownload
                    let prev = intervals[0];
                    let res = [prev];
                    
                    console.log(prev === res[0]); // true
                    console.log(prev === intervals[0]); // true
                    console.log(res[0] === intervals[0]); // true
                    
                    prev = 'something else';
                    console.log(prev === res[0]); // FALSE
                    console.log(prev === intervals[0]); // FALSE
                    console.log(res[0] === intervals[0]); // true
                    
                    let prev = intervals[0];
                    let res = [prev];
                    
                    console.log(prev === res[0]); // true
                    console.log(prev === intervals[0]); // true
                    console.log(res[0] === intervals[0]); // true
                    
                    prev = 'something else';
                    console.log(prev === res[0]); // FALSE
                    console.log(prev === intervals[0]); // FALSE
                    console.log(res[0] === intervals[0]); // true
                    
                    let prev = intervals[0];
                    let res = [prev];
                    
                    console.log(prev === res[0]); // true
                    console.log(prev === intervals[0]); // true
                    console.log(res[0] === intervals[0]); // true
                    
                    prev = 'something else';
                    console.log(prev === res[0]); // FALSE
                    console.log(prev === intervals[0]); // FALSE
                    console.log(res[0] === intervals[0]); // true
                    

                    How can I label connected components in APL?

                    copy iconCopydownload iconDownload
                          ⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 3 0 4
                    0 5 0 0 6
                    0 7 0 0 8
                    
                            {⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 4
                    0 2 0 0 4
                    0 2 0 0 4
                    
                            (∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    1 1 2 1 1
                    1 1 1 1 1
                    1 3 3 1 4
                    1 3 1 1 4
                    1 3 1 1 4
                    
                            ¯1+(∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 3
                    0 2 0 0 3
                    0 2 0 0 3
                    
                          ⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 3 0 4
                    0 5 0 0 6
                    0 7 0 0 8
                    
                            {⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 4
                    0 2 0 0 4
                    0 2 0 0 4
                    
                            (∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    1 1 2 1 1
                    1 1 1 1 1
                    1 3 3 1 4
                    1 3 1 1 4
                    1 3 1 1 4
                    
                            ¯1+(∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 3
                    0 2 0 0 3
                    0 2 0 0 3
                    
                          ⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 3 0 4
                    0 5 0 0 6
                    0 7 0 0 8
                    
                            {⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 4
                    0 2 0 0 4
                    0 2 0 0 4
                    
                            (∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    1 1 2 1 1
                    1 1 1 1 1
                    1 3 3 1 4
                    1 3 1 1 4
                    1 3 1 1 4
                    
                            ¯1+(∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 3
                    0 2 0 0 3
                    0 2 0 0 3
                    
                          ⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 3 0 4
                    0 5 0 0 6
                    0 7 0 0 8
                    
                            {⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 4
                    0 2 0 0 4
                    0 2 0 0 4
                    
                            (∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    1 1 2 1 1
                    1 1 1 1 1
                    1 3 3 1 4
                    1 3 1 1 4
                    1 3 1 1 4
                    
                            ¯1+(∪⍤,⍳⊢){⌊/⍵[2;2],0~⍨⊢/4 2⍴⍵}⌺3 3⍣≡⍸@⊢m
                    0 0 1 0 0
                    0 0 0 0 0
                    0 2 2 0 3
                    0 2 0 0 3
                    0 2 0 0 3
                    

                    Longest Common Prefix in Javascript

                    copy iconCopydownload iconDownload
                    strs[i][j] == strs[i + 1][j] ==strs[i + 2][j]
                    
                    strs[i][j] == strs[i + 1][j] && strs[i + 1][j] ==strs[i + 2][j]
                    
                    let strs = ["flower", "flow", "flight", "dix"];
                    
                    function longestCommonPrefix (strs) {
                      // loop over the characters of the first element
                      for (let j = 0; j < strs[0].length; j++) {
                        // ignore the first elements since is obvious that is equal to itself
                        for (let i = 1; i < strs.length; i++) {
                           /* in case you have like 
                            [
                              'banana',
                              'bana'
                            ]
                            the longest prefix is the second element
                           */
                           if(j >= strs[i].length){
                             return strs[i]
                           }
                           // different i-th element
                           if(strs[0][j] != strs[i][j]){
                             return strs[0].substr(0, j)
                           }
                           
                        }
                      }
                      // all good, then the first element is common to all the other elements
                      return strs[0]
                    };
                    
                    console.log(longestCommonPrefix(strs));
                    strs[i][j] == strs[i + 1][j] ==strs[i + 2][j]
                    
                    strs[i][j] == strs[i + 1][j] && strs[i + 1][j] ==strs[i + 2][j]
                    
                    let strs = ["flower", "flow", "flight", "dix"];
                    
                    function longestCommonPrefix (strs) {
                      // loop over the characters of the first element
                      for (let j = 0; j < strs[0].length; j++) {
                        // ignore the first elements since is obvious that is equal to itself
                        for (let i = 1; i < strs.length; i++) {
                           /* in case you have like 
                            [
                              'banana',
                              'bana'
                            ]
                            the longest prefix is the second element
                           */
                           if(j >= strs[i].length){
                             return strs[i]
                           }
                           // different i-th element
                           if(strs[0][j] != strs[i][j]){
                             return strs[0].substr(0, j)
                           }
                           
                        }
                      }
                      // all good, then the first element is common to all the other elements
                      return strs[0]
                    };
                    
                    console.log(longestCommonPrefix(strs));
                    strs[i][j] == strs[i + 1][j] ==strs[i + 2][j]
                    
                    strs[i][j] == strs[i + 1][j] && strs[i + 1][j] ==strs[i + 2][j]
                    
                    let strs = ["flower", "flow", "flight", "dix"];
                    
                    function longestCommonPrefix (strs) {
                      // loop over the characters of the first element
                      for (let j = 0; j < strs[0].length; j++) {
                        // ignore the first elements since is obvious that is equal to itself
                        for (let i = 1; i < strs.length; i++) {
                           /* in case you have like 
                            [
                              'banana',
                              'bana'
                            ]
                            the longest prefix is the second element
                           */
                           if(j >= strs[i].length){
                             return strs[i]
                           }
                           // different i-th element
                           if(strs[0][j] != strs[i][j]){
                             return strs[0].substr(0, j)
                           }
                           
                        }
                      }
                      // all good, then the first element is common to all the other elements
                      return strs[0]
                    };
                    
                    console.log(longestCommonPrefix(strs));
                    let strs = ["flower", "flow", "flight"];
                    
                    var longestCommonPrefix = function (strs) {
                      for (let i = 0; i < strs.length; i++) {
                        for (let j = 0; j < strs[i].length; j++) {
                            console.log(strs[i+2][j]);
                          if (strs[i][j] == strs[i + 1][j] && strs[i][j]  ==strs[i + 2][j]) {
                            return (strs[i][j]);
                            
                    
                    
                          } else {
                            return "0";
                          }
                        }
                      }
                    };
                    
                    console.log(longestCommonPrefix(strs));
                    
                    var longestCommonPrefix = function(strs) {
                        let prefix = strs.reduce((acc, str) => str.length < acc.length ? str : acc);
                        
                        for (let str of strs) {
                            while (str.slice(0, prefix.length) != prefix) {
                                prefix = prefix.slice(0, -1);
                            }
                        }
                        return prefix;
                    };
                    
                    let res = longestCommonPrefix(["flower","flow","flight"]);
                    
                    console.log(res);
                    function prefix(words){
                      // check border cases size 1 array and empty first word)
                      if (!words[0] || words.length ==  1) return words[0] || "";
                      let i = 0;
                      // while all words have the same character at position i, increment i
                      while(words[0][i] && words.every(w => w[i] === words[0][i]))
                        i++;
                      
                      // prefix is the substring from the beginning to the last successfully checked i
                      return words[0].substr(0, i);
                    }
                    
                    console.log(1, prefix([]));
                    console.log(2, prefix([""]));
                    console.log(3, prefix(["abc"]));
                    console.log(4, prefix(["abcdefgh", "abcde", "abe"]));
                    console.log(5, prefix(["abc", "abc", "abc"]));
                    console.log(6, prefix(["abc", "abcde", "xyz"]));
                    function longestPrefix(strs){
                        if(strs.length <1){
                            return "";
                        }
                        const sharedPrefix=function(str1,str2){
                            let i=0;
                            for(;i<Math.min(str1.length,str2.length) /*todo optimize*/;++i){
                                if(str1[i] !== str2[i]){
                                    break;
                                }
                            }
                            return str1.substr(0,i);
                        };
                        let curr = strs[0];
                        for(let i=1;i<strs.length;++i){
                            curr=sharedPrefix(curr,strs[i]);
                            if(curr.length < 1){
                                // no shared prefix
                                return "";
                            }
                        }
                        return curr;
                    }
                    
                    function longestCommonPrefix(arr) {
                      const charList = [];
                    
                      const [shortestWord, ...wordList] =
                        // sort shallow copy by item `length` first.
                        [...arr].sort((a, b) => a.length - b.length);
                    
                      shortestWord
                        .split('')
                        .every((char, idx) => {
                          const isValidChar = wordList.every(word =>
                            word.charAt(idx) === char
                          );
                          if (isValidChar) {
                            charList.push(char);
                          }
                          return isValidChar;
                        });
                    
                      return charList.join('');
                    }
                    
                    console.log(
                      longestCommonPrefix(["flower","flow","flight"])
                    );
                    .as-console-wrapper { min-height: 100%!important; top: 0; }
                    function longestCommonPrefix(arr) {
                      const charList = [];
                    
                      const [shortestWord, ...wordList] =
                        // sort shallow copy by item `length` first.
                        [...arr].sort((a, b) => a.length - b.length);
                    
                      shortestWord
                        .split('')
                        .every((char, idx) => {
                          const isValidChar = wordList.every(word =>
                            word.charAt(idx) === char
                          );
                          if (isValidChar) {
                            charList.push(char);
                          }
                          return isValidChar;
                        });
                    
                      return charList.join('');
                    }
                    
                    console.log(
                      longestCommonPrefix(["flower","flow","flight"])
                    );
                    .as-console-wrapper { min-height: 100%!important; top: 0; }
                    function prefix(words) {
                      if (words.length === 0) { return '' }
                      let index = 0;
                      while (allSameAtIndex(words, index)) {
                        index++;
                      }
                      return words[0].slice(0, index);
                    }
                    
                    function allSameAtIndex(words, index) {
                      let last;
                      for (const word of words) {
                        if (last !== undefined && word[index] !== last[index]) {
                          return false;
                        }
                        last = word;
                      }
                      return true;
                    }
                    
                    var longestCommonPrefix = function(strs) {
                    let arr = strs.concat().sort();
                    const a1 = arr[0];
                    const a2 = arr[arr.length -1];
                    const length = a1.length;
                    let i=0;
                    
                    while(i<length && a1.charAt(i) == a2.charAt(i)) i++;
                    return a1.substring(0,i);
                    
                    };
                    
                    function prefixLen(s1, s2) {
                        let i = 0;
                        while (i <= s1.length && s1[i] === s2[i]) i++;
                        return i;
                    }
                    
                    function commonPrefix(arr) {
                        let k = prefixLen(arr[0], arr[1]);
                        for (let i = 2; i < arr.length; i++) {
                            k = Math.min(k, prefixLen(arr[0], arr[i]));
                        }
                        return arr[0].slice(0, k);
                    }
                    
                    console.log(commonPrefix(['pirate', 'pizza', 'pilates']))  // -> "pi"
                    var longestCommonPrefix = function(strs) {
                        let prefix = "";
                        for(let i = 0; i < strs[0].length; i++) {
                            for(let j = 1; j < strs.length; j++) {
                                if(strs[j][i] !== strs[0][i]) return prefix;
                            }
                            prefix = prefix + strs[0][i];
                        }
                        return prefix;
                    };
                    console.log(longestCommonPrefix);
                    

                    Binary Search in JS: trying to find a consistent mental model

                    copy iconCopydownload iconDownload
                    if(nums[mid] > nums[mid + 1]) {
                    
                    var findPeakElement = function(nums) {
                        let left = 0,
                            right = nums.length - 1;
                    
                        while (left < right) {
                            const mid = (left + right) >>> 1;
                            if (nums[mid] > nums[mid + 1]) {
                                right = mid;
                            } else {
                                left = mid + 1;
                            }
                        }
                    
                        return left;
                    };
                    
                    if(nums[mid] > nums[mid + 1]) {
                    
                    var findPeakElement = function(nums) {
                        let left = 0,
                            right = nums.length - 1;
                    
                        while (left < right) {
                            const mid = (left + right) >>> 1;
                            if (nums[mid] > nums[mid + 1]) {
                                right = mid;
                            } else {
                                left = mid + 1;
                            }
                        }
                    
                        return left;
                    };
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                            5,
                              4,        4,
                          3,          3,  3,
                        2,      2,  2,      2 ]
                    [ 1,          1,
                    
                    function* peaks ([ a, b, c, ...more ]) {
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks([ b, c, ...more ])                 // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t, i = 0) {
                      let a = t[i], b = t[i + 1], c = t[i + 2]
                      if (a == null || b == null || c == null) return // 1
                      if (a < b && b > c) yield b                     // 2
                      yield *peaks(t, i + 1)                          // 3
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = t[i], b = t[i + 1], c = t[i + 2]
                        if (a == null || b == null || c == null) return // 1
                        if (a < b && b > c) yield b                     // 2
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (let i = 0; i<t.length; i++) {
                        a = b, b = c, c = t[i]
                        if (a == null || b == null || c == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    function* peaks (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) yield b
                      }
                    }
                    
                    for (const p of peaks([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                      console.log("found peak", p)
                    found peak 2
                    found peak 5
                    found peak 7
                    
                    const allPeaks = peaks([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    console.log(allPeaks)
                    
                    [2, 5, 7]
                    
                    const firstPeak (t) {
                      for (const p of peaks(t))
                        return p                 // <- immediately stops `peaks`
                    }
                    
                    firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4])
                    
                    2
                    
                    function firstPeak (t) {
                      let a, b, c
                      for (const v of t) {
                        a = b, b = c, c = v
                        if (a == null || b == null) continue
                        if (a < b && b > c) return b          // <-
                      }
                    }
                    
                    console.log("first peak", firstPeak([1,2,1,3,4,5,4,2,1,5,6,7,4]))
                    first peak 2
                    
                    def f(arr)
                      0.upto(998) do |i|
                        return arr[i] if arr[i+1] < arr[i]
                      end
                      return arr[999] # if we reach this, arr[998] < arr[999] and arr[1000] is -infinity
                    end
                    

                    Saddleback search starting point

                    copy iconCopydownload iconDownload
                    i+j < k
                    i+j > k
                    i+j == k
                    

                    Is x%(1e9 + 7) and x%(10**9 + 7) different in Python? If yes, why?

                    copy iconCopydownload iconDownload
                    >>> int(123123123123123123123.0)
                    123123123123123126272
                    #                ^^^^ different!
                    
                    >>> int(123123123123123123123)
                    123123123123123123123
                    
                    >>> 123123123123123123123 % 10**9
                    123123123
                    
                    >>> 123123123123123123123 % 1e9
                    123126272.0
                    
                    >>> int(123123123123123123123.0)
                    123123123123123126272
                    #                ^^^^ different!
                    
                    >>> int(123123123123123123123)
                    123123123123123123123
                    
                    >>> 123123123123123123123 % 10**9
                    123123123
                    
                    >>> 123123123123123123123 % 1e9
                    123126272.0
                    
                    >>> int(123123123123123123123.0)
                    123123123123123126272
                    #                ^^^^ different!
                    
                    >>> int(123123123123123123123)
                    123123123123123123123
                    
                    >>> 123123123123123123123 % 10**9
                    123123123
                    
                    >>> 123123123123123123123 % 1e9
                    123126272.0
                    

                    How to remove all instances of a duplicate from a vector&lt;int&gt;

                    copy iconCopydownload iconDownload
                    #include <unordered_map>
                    ...
                    
                    std::unordered_map<int, bool> uniqueCheckMap;
                    for (auto i : nums)
                    {
                        if (uniqueCheckMap.find(i) == uniqueCheckMap.end())
                            uniqueCheckMap[i] = false;
                        else
                            uniqueCheckMap[i] = true;    // Set the second (value) as true if duplicate entry is found.
                    }
                    
                    nums.clear();
                    int sum = 0;
                    for (auto i : uniqueCheckMap)
                    {
                        if (!i.second)
                        {
                            nums.push_back(i.first);
                            sum += i.first;
                        }
                    }
                    
                    #include <set>
                    #include <vector>
                    
                    int main()
                    {
                        std::vector<int> nums = {1,2,2,3,5};
                    
                        std::multiset<int> m (nums.begin(), nums.end());
                    
                        std::size_t sum = 0;
                        for (const auto& elem : m)
                        {
                          sum += m.count(elem) == 1 ? elem : 0;
                        }
                    }
                    
                    if(!map[number]){
                    set.insert(number);
                    map[number]=true;
                    }else{
                    set.erase(number);
                    }
                    
                    const auto sum=std::accumulate(cbegin(nums), cend(nums), 0,
                      [&](const auto &accum, const auto &elem)
                      {
                        return accum+(std::count(cbegin(nums), cend(nums), elem)>1 ? 0 : elem);
                      });
                    
                            auto ints = vector{4, 3, 2, 2, 1};
                    
                            sort(begin(ints), end(ints));
                            std::vector<int> unique_ints;
                            unique_copy(begin(ints), end(ints), back_inserter(unique_ints));
                    
                            vector<int> doubles;
                            set_difference( begin(ints), end(ints),
                                            begin(unique_ints), end(unique_ints),
                                            back_inserter(doubles)
                                            );
                    
                            vector<int> only_once;
                            set_difference( begin(unique_ints), end(unique_ints),
                                            begin(doubles), end(doubles),
                                            back_inserter(only_once));
                    
                            copy(begin(only_once), end(only_once), ostream_iterator<int>(cout, ", "));
                            cout << "\n";
                    
                    
                    $ g++ -std=c++17 u.cpp  && ./a.out 
                    1, 3, 4, 
                    
                            auto ints = vector{4, 3, 2, 2, 1};
                    
                            sort(begin(ints), end(ints));
                            std::vector<int> unique_ints;
                            unique_copy(begin(ints), end(ints), back_inserter(unique_ints));
                    
                            vector<int> doubles;
                            set_difference( begin(ints), end(ints),
                                            begin(unique_ints), end(unique_ints),
                                            back_inserter(doubles)
                                            );
                    
                            vector<int> only_once;
                            set_difference( begin(unique_ints), end(unique_ints),
                                            begin(doubles), end(doubles),
                                            back_inserter(only_once));
                    
                            copy(begin(only_once), end(only_once), ostream_iterator<int>(cout, ", "));
                            cout << "\n";
                    
                    
                    $ g++ -std=c++17 u.cpp  && ./a.out 
                    1, 3, 4, 
                    
                            sort(begin(ints), end(ints));
                    
                            int acc = 0;
                            auto range = equal_range(begin(ints), end(ints), ints.front());
                    
                            while(range.first != end(ints)) {
                                    cout << *range.first << "+ ";
                                    if (distance(range.first, range.second) == 1){
                                            acc += *range.first;
                                    }
                                    range = equal_range(range.second, end(ints), *range.second);
                            }
                            cout << " = " << acc << "\n";
                    

                    Write 4 : 'x&amp;{.&amp;.;: y' tacitly

                    copy iconCopydownload iconDownload
                       solve =: 1 : 'm&{.&.;:'
                       4 solve
                    4&{.&.;:
                       (4 solve ,: 2 solve) 'Hello how are you Contestant'
                    Hello how are you
                    Hello how        
                    

                    See all related Code Snippets

                    Community Discussions

                    Trending Discussions on leetcode
                    • Using while let with two variables simultaneously
                    • F2 rename variable doesn't work in vscode + jupyter notebook + python
                    • Is this Union Find really O(n) as they claim?
                    • Are java streams able to lazilly reduce from map/filter conditions?
                    • How are javascript variables referenced?
                    • Will std::sort always compare equal values?
                    • How can I label connected components in APL?
                    • Understanding left hand notation of C(n,2)= n(n−1)​ / 2
                    • Longest Common Prefix in Javascript
                    • Binary Search in JS: trying to find a consistent mental model
                    Trending Discussions on leetcode

                    QUESTION

                    Using while let with two variables simultaneously

                    Asked 2022-Apr-10 at 08:55

                    I'm learning Rust and have been going through leetcode problems. One of them includes merging two linked lists, whose nodes are optional. I want to write a while loop that would go on until at least 1 node becomes None, and I was trying to use the while let loop for that.

                    However, it looks like the while let syntax supports only one optional, e.g.:

                    while let Some(n) = node {
                       // do stuff
                    }
                    

                    but I can't write

                    while let Some(n1) = node1 && Some(n2) = node2 {
                    }
                    

                    Am I misunderstanding the syntax? I know I can rewrite it with a while true loop, but is there a more elegant way of doing it?

                    Also, can one do multiple checks with if let? Like if let None=node1 && None=node2 {return}

                    ANSWER

                    Answered 2022-Apr-10 at 08:22

                    You can pattern match with Option::zip:

                    while let Some((n1, n2)) = node1.zip(node2) {
                        ...
                    }
                    

                    Source https://stackoverflow.com/questions/71814858

                    Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                    Vulnerabilities

                    No vulnerabilities reported

                    Install leetcode

                    You can download it from GitHub.

                    Support

                    For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

                    DOWNLOAD this Library from

                    Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                    over 430 million Knowledge Items
                    Find more libraries
                    Reuse Solution Kits and Libraries Curated by Popular Use Cases
                    Explore Kits

                    Save this library and start creating your kit

                    Share this Page

                    share link
                    Consider Popular Learning Libraries
                    Try Top Libraries by azl397985856
                    Compare Learning Libraries with Highest Support
                    Compare Learning Libraries with Highest Quality
                    Compare Learning Libraries with Highest Security
                    Compare Learning Libraries with Permissive License
                    Compare Learning Libraries with Highest Reuse
                    Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                    over 430 million Knowledge Items
                    Find more libraries
                    Reuse Solution Kits and Libraries Curated by Popular Use Cases
                    Explore Kits

                    Save this library and start creating your kit

                    • © 2022 Open Weaver Inc.