-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
#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 | ||
K = 3 | ||
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() | ||
|
||
|
||
|