Sort by

recency

|

93 Discussions

|

  • + 0 comments

    Only change 3 lines but doesn't provide all languages. So if you make a new solution from scratch, your solution always fails due to creating more than 3 lines of code.

  • + 0 comments

    Python 3 (comments on changed lines)

    def findZigZagSequence(a, n):
        a.sort()
        mid = int((n + 1)/2) - 1 #Used as index, so -1
        a[mid], a[n-1] = a[n-1], a[mid]
    
        st = mid + 1
        ed = n - 2 #The last element is already in place, thus n-2
        while(st <= ed):
            a[st], a[ed] = a[ed], a[st]
            st = st + 1
            ed = ed - 1 #Decreasing
    
        for i in range (n):
            if i == n-1:
                print(a[i])
            else:
                print(a[i], end = ' ')
        return
    
    test_cases = int(input())
    for cs in range (test_cases):
        n = int(input())
        a = list(map(int, input().split()))
        findZigZagSequence(a, n)
    
  • + 1 comment

    i have made my solution in c and it's workig with the exact output when debuging on codeblocks but when submitting it on the site it gives me wrong answer

  • + 0 comments

    Although the expected output is matching with my output it's not passing. def findZigZagSequence(a, n): a.sort()#Sorting the array mid = int(n/2)#Finding the middle element a[mid], a[n-1] = a[n-1], a[mid] #Swapping the middle element with the max number #print(a) st = mid + 1 ed = n - 2 while(st <= ed): a[st], a[ed] = a[ed], a[st] st = st + 1 ed = ed - 1

    for i in range (n):
        if i == n-1:
            print(a[i])
        else:
            print(a[i], end = ' ')
    return
    

    test_cases = int(input()) for cs in range (test_cases): n = int(input()) a = list(map(int, input().split())) findZigZagSequence(a, n)

  • + 2 comments

    I am not sure how to make this 3 lines or less in JS and there is no findZigZagSequence function to debug, but here's my solution (which isn't passing despite the output matching what is expected 🤔) I feel like this is fairly sloppy though.

    function processData(input) {
        const modifiedInput = input.split('\n')
        const middlePosition = Math.floor(modifiedInput[1] / 2)
        const sortedArr = modifiedInput[2].split(' ').sort((a,b) => a-b)
        const middleNumber = sortedArr.pop()
        const resultingArray = []
        for (let a = 0; a < middlePosition; a++) {
            resultingArray.push(sortedArr[a])
        }
        const reversedArray = sortedArr.reverse()
        resultingArray.push(middleNumber)
        for (let a = 0; a < middlePosition; a++) {
            resultingArray.push(reversedArray[a])
        }
        console.log(resultingArray.join(' '))
        return resultingArray.join(' ')
    } 
    `