#Reverse array in #groups in Hindi | Cpp/Java | #gfgsdesheet | Simple Explanation

preview_player
Показать описание
Hello, I am Neeraj Mahapatra,

Today we are going to learn about Reverse array in groups in Hindi.
Given an array arr[] of positive integers of size N. Reverse every sub-array group of size K.

Note: If at any instance, there are no more subarrays of size greater than or equal to K, then reverse the last subarray (irrespective of its size). You shouldn't return any array, modify the given array in-place.

Time Stamps:-
00:00-Intro
00:05 - Question Explanation
01:31 - Concept Explanation
09:04 - Java Code
11:33 - Cpp Code

#cpp #java #programming #reversearray #reversearrayingroup #gfgsdesheet #striversdesheet #babbardsasheet
Hope you like this video...
Please SUBSCRIBE, LIKE AND COMMENT...
Share to show Support..

Support us !!!.....Thanks....❤
Рекомендации по теме
Комментарии
Автор

Logic seems correct but ur code will give error when reversing with second Method reason: because arr is an ArrayList<Integer>, not an array, so we need to use the get() and set() methods instead of indexing in java.

correct reversing (just in case, if one don't want to use inbuilt swap method ) would be
while(start_index <= end_index){
int temp = arr.get(end_index);
arr.set(end_index, arr.get(start_index));
arr.set(start_index, temp);
start_index++;end_index--;
}

ananya_sinha
welcome to shbcf.ru