maxLengthTuringAlghoritm.js

    0

    0

    The code finds the maximum value of an array A, using a for-loop. The maximum value is found at position i, inclusive, and is the largest value of A[i] + A[j] that is not greater than K.

    function solution(A, K) {
      let max = 0;
      for (let i = 0; i < A.length; i++) {
        for (let j = i + 1; j < A.length; j++) {
          if (A[i] + A[j] < K) {
            max = Math.max(max, A[i] + A[j]);
          }
        }
      }
      return max === 0 ? -1 : max;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.