Zig Zag Sequence

Sort by

recency

|

915 Discussions

|

  • + 0 comments

    I dont understand the problem, the explanation is laking for details in my oppinion.

  • + 0 comments

    Broken in JS but here is my solution

    function processData(input) {
        const arrStartIndex = input.lastIndexOf('\n');
        const finalArr = input.substring(arrStartIndex + 1).split(' ');
        const sortedArr = finalArr.sort((a, b) => a - b);
        const middleNumber = (sortedArr.length / 2)
        const secondHalf = sortedArr.slice(middleNumber)
        const firstHalf = sortedArr.slice(0, middleNumber)
        const result= [...firstHalf, ...secondHalf.reverse()].join(' ')
        return result;
    }
    
  • + 0 comments

    My results are the same as expected, but it says it is incorrect

  • + 0 comments

    it is broken in js :(

       const [_, length, rawArr] = input.split('\n');
    
    const arr = rawArr.split(' ').sort((a, b) => a - b);
    
    
    let mid = Math.floor(length / 2);
    
    [arr[mid], arr[length - 1]] = [arr[length - 1], arr[mid]]
    
    let left = mid + 1;
    let right = length - 2;
    while (left < right) {
        [arr[left], arr[right]] = [arr[right], arr[left]];
        left++;
        right--;
    }
    
    const str = arr.join(' ');
    const strTrim = str.trim();
    
    
    console.log(strTrim);
    
  • + 0 comments

    This challange is broken for multiple languages and, well, that's just sad