Back to course home
0% completed
Vote For New Content
O(N) solution without divide and conquer
shripadtheneo
Oct 18, 2024
class Solution: def beautifulArray(self, N: int) -> [int]: result = [0] * N if N == 1: return[1] print(result) for i in range(0, N, 2): if i+1 < N: result[i] = i+2 result[i+1] = i+1 else: result[i] = i+1 print(result) # ToDo: Write Your Code Here. return result
1
0
Comments
Comments
Shubham Voraa year ago
For n = 5, it gives [2,1,4,3,5] output, which is wrong as A[3]*2 = A[1] + A[4].