Zig Zag Sequence

Sort by

recency

|

153 Discussions

|

  • + 0 comments

    hackerrank should fix their stuff, there's no code in c#

  • + 0 comments

    am getting same output but it's shows wrong answer why ??

    include

    include

    include

    include

    int main() {

    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    int temp, mid, l, n, k;
    scanf("%d",&l);
    scanf("%d",&n);
    int a[n];
    for(int i=0; i<n; i++){
        scanf("%d",&a[i]);
    }
    k=(n+1)/2;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++)
        {
            if(a[i]>a[j]){
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }
    
    int temp1=a[k-1];
        a[k-1]=a[n-1];
        a[n-1]=temp1;
        int j=n-2;
    while(k<=j){
        int temp3=a[k];
        a[k]=a[j];
        a[j]=temp3;
        k++;
        j--;
    }
    
    
    for(int i=0;i<n; i++){
        printf("%d",a[i]);
        printf(" ");
    }
    
    return 0;
    

    }

  • + 0 comments

    The findZigZagSequence function is not provided.

  • + 1 comment

    The example provided in description seems misleading, for[2,3,1,5,4]the correct output is [1,2,5,4,3] , however in description we have [1,4,5,3,2] (altough it is mentioned it is a zigzag sequence).

    It would be better the descrption updated to say: the correct expected sequence in this case is [1,2,5,4,3]

  • + 1 comment

    If you change more than 3 lines of code it will fail, even if response is correct!