Zig Zag Sequence

Sort by

recency

|

142 Discussions

|

  • + 0 comments

    I needed to write all the code (in C#) including parsing the command line input, and passing it to a zigzagSequence function that I wrote from scratch.

    My output matches the expected output but looks like the checker is looking for some metadata about the csharp that hackerrank should have set up.

    So this question is fundamentally broken.

  • + 0 comments

    Tried to solve in go, but I'm receiving this: Traceback (most recent call last): File "Solution.py", line 178, in run_custom_checker(t_obj, r_obj) File "Solution.py", line 77, in run_custom_checker system_code = code_data[t_obj.submission_language].strip() KeyError: u'go'

  • + 0 comments

    Does not work in go

  • + 0 comments

    I found the correct code for java. I was struggling as everyone here, and understood that we should not right the code to solve the problem, we only need to change the given code to get the correct output.

    import java.util.*;
    import java.lang.*;
    import java.io.*;
    import java.math.*;
    public class Main {
        
        public static void main (String[] args) throws java.lang.Exception {
            Scanner kb = new Scanner(System.in);
            int test_cases = kb.nextInt();
            for(int cs = 1; cs <= test_cases; cs++){
                int n = kb.nextInt();
                 int a[] = new int[n];
                for(int i = 0; i < n; i++){
                    a[i] = kb.nextInt();
                }
                findZigZagSequence(a, n);
            }
       }
       
        public static void findZigZagSequence(int [] a, int n){
            Arrays.sort(a);
            int mid = n /2; //first change
            int temp = a[mid];
            a[mid] = a[n - 1];
            a[n - 1] = temp;
        
            int st = mid + 1;
            int ed = n - 2; //second change
            while(st <= ed){
                temp = a[st];
                a[st] = a[ed];
                a[ed] = temp;
                st = st + 1;
                ed = ed - 1; //third change
            }
            for(int i = 0; i < n; i++){
                if(i > 0) System.out.print(" ");
                System.out.print(a[i]);
            }
            System.out.println();
        }
    }
    
  • + 1 comment

    I am using pyhon. I believe my solution is right. I only change 3 lines of code. Still I can't get this to work.