Zig Zag Sequence

Sort by

recency

|

74 Discussions

|

  • + 0 comments

    In java with Java 8 only there not problem Only 3 lines

    int mid = (n)/2;
            int temp = a[mid];
            a[mid] = a[n - 1];
            a[n - 1] = temp;
        
            int st = mid + 1;
            int ed = n - 2;
            while(st <= ed){
                temp = a[st];
                a[st] = a[ed];
                a[ed] = temp;
                st = st + 1;
                ed = ed - 1;
            }
    
  • + 0 comments

    " Now if we permute the array as [1,4,5,3,2] , the result is a zig zag sequence. " This will NOT be the resutl given the input in the example. So it was a very confusing exmaple to give. If you first sort the array clearly this isn't a good output.

  • + 0 comments

    this worked(C++11) void findZigZagSequence(vector < int > a, int n){ sort(a.begin(), a.end()); int mid = (n)/2; swap(a[mid], a[n-1]);

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

    }

  • + 1 comment

    Hi, I'm having an issue with the test cases for ts even the result and expected output is the same. someone nows how to fix this?

    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'typescript'

  • + 0 comments

    C++20 Has no code to debug