diff --git a/reverse_array_in_groups/raig.py b/reverse_array_in_groups/raig.py index 52eabeb..5d43a84 100644 --- a/reverse_array_in_groups/raig.py +++ b/reverse_array_in_groups/raig.py @@ -1,13 +1,20 @@ #User function template for Python +global arr class Solution: - #Function to reverse every sub-array group of size k. - def reverseInGroups(self, arr, N, K): - print("ana are mere") - for x in arr: - print(x) - # code here + def chunker(self, seq, size): + return (seq[pos:pos + size] for pos in range(0, len(seq), size)) + def reverseInGroups(self, arr, N, K): + newArr=[] + for x in self.chunker(list(arr),K): + for i, e in reversed(list(enumerate(x))): + newArr.append(e) + print(e,end=" ") + print() + arr=set(newArr) + return arr + import math def main(): N = 5 @@ -15,7 +22,11 @@ def main(): arr = {1,2,3,4,5} ob = Solution() ob.reverseInGroups(arr,N,K) + for i in arr: + print(i,end=" ") + print() if __name__=="__main__": main() - \ No newline at end of file + + \ No newline at end of file