Zig Zag Sequence

Sort by

recency

|

1030 Discussions

|

  • + 0 comments

    In Python 3, you need to change lines 3, 7, and 11.

    1. line 3 - our indexing starts at 0 so you need to change the formula to accommodate such condition
    2. line 7 - ed should start at the 2nd to the last element, not the last element because you already swapped the last element to the mid element
    3. line 11 - ed should decrease so that the loop condition will end
  • + 0 comments

    i tried in python c# java 8 output is correct still it is showing wrong answer

    does anyone have idea why?

  • + 0 comments

    Python 3 didn't work but Java 8 worked.

  • + 0 comments

    Does anyone know if this answer supports Ruby? I keep getting the 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'ruby'

  • + 0 comments

    Java 8: public static void findZigZagSequence(int [] a, int n){ Arrays.sort(a); int mid = (n - 1)/2;// first modified int temp = a[mid]; a[mid] = a[n - 1]; a[n - 1] = temp;

        int st = mid + 1;
        int ed = n - 2;//second modified
        while(st <= ed){
            temp = a[st];
            a[st] = a[ed];
            a[ed] = temp;
            st = st + 1;
            ed = ed - 1;// modified
        }
        for(int i = 0; i < n; i++){
            if(i > 0) System.out.print(" ");
            System.out.print(a[i]);
        }
        System.out.println();
    }
    

    }