Zig Zag Sequence

Sort by

recency

|

991 Discussions

|

  • + 1 comment

    void findZigZagSequence(vector &a, int n) { sort(a.begin(), a.end()); int mid = (n-1)/2; swap(a[mid], a[n-1]);

    int st = mid+1;
    int ed =n-2;  
    
    while (st < ed) {
        swap(a[st], a[ed]);
        st++;
        ed--;
    }
    for (int i=0; i<n; i++) {
        if (i>0) cout << " ";
        cout<<a[i];
    }
    cout<<endl;
    

    }

  • + 0 comments

    function findZigZagSequence(arr, n){ arr.sort((a,b)=> a-b);

    let k = Math.floor((n+1)/2) - 1;
    [arr[k], arr[n-1]] = [arr[n-1], arr[k]];
    
    let left = k+1, right = n-2;
    while(left<right){
        [arr[left], arr[right]] = [arr[right], arr[left]]
        left++;
        right--;
    }
    const arry = arr.join(' ')
    console.log(arry)
    

    }

    function processData(input) { //Enter your code here let lines = input.trim().split('\n') let t = parseInt(lines[0]); let index = 1; for(let i=0; i

    }

    process.stdin.resume(); process.stdin.setEncoding("ascii"); _input = ""; process.stdin.on("data", function (input) { _input += input; });

    process.stdin.on("end", function () { processData(_input); });

    Compiler Message Custom checker Failed: Success Input (stdin) 1 7 1 2 3 4 5 6 7 Your Output (stdout) 1 2 3 7 6 5 4 Expected Output 1 2 3 7 6 5 4 Custom Checker Error Message Traceback (most recent call last): File "Solution.py", line 174, in run_custom_checker(t_obj, r_obj) File "Solution.py", line 75, in run_custom_checker system_code = code_data[t_obj.submission_language].strip() KeyError: u'javascript'

  • + 0 comments

    I was stuck on the test case where even though the output result and the expected result was the same, it was flagged as incorrect. If you only edit three parts of the code, it works.

  • + 0 comments

    My answer is the same of the resolution, but is not acepted as correct, why? I made my test on python

  • + 3 comments

    I think something is not well on this problem, I'm trying with C#, on test I have the expected output but bellow this error:

    Traceback (most recent call last): File "Solution.py", line 174, in run_custom_checker(t_obj, r_obj) File "Solution.py", line 75, in run_custom_checker system_code = code_data[t_obj.submission_language].strip() KeyError: u'csharp'