FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp/F12Array-2/ReverseArrayBetween2Index.cpp at main · roydevashish/cpp · GitHub
roydevashish
/
cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp
/
F12Array-2
/
ReverseArrayBetween2Index.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
111 lines (87 loc) · 2.3 KB
Breadcrumbs
cpp
/
F12Array-2
/
ReverseArrayBetween2Index.cpp
Copy path
File metadata and controls
111 lines (87 loc) · 2.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
Title: Reverse Array Between 2 Index
Problem statement
Given an array ‘ARR’ of size ‘N’. You are also given two indices ‘L’ and ‘R’.
Your task is to reverse the ‘ARR’ from index ‘L’ to ‘R’ inclusive.
Example:
Input:
‘N’ = 3 ‘L’ = 0 ‘R’ = 1 ‘ARR’ = [1, 2, 3]
Output:
2 1 3
Explanation:
When we reverse the elements between indices 0 and 1 we get the array as 2 1 3.
Detailed explanation ( Input/output format, Notes, Images )
Input Format:
The first line of input contains an integer ‘T’ denoting the number of test cases.
Then the test case follows.
The first line of each test case contains an integer ‘N’ denoting the number of elements in the array ‘ARR’.
The second line of each test case contains 2 space-separated integers denoting ‘L’ and ‘R’ respectively.
The second line of each test case contains ‘N' space-separated integers denoting the elements of the array ‘ARR’.
Output format:
For each test case print the array after applying the given operation.
Constraints :
1 <= T <= 10
1 <= N <= 100000
0 <= L, R < N
1 <= ARR[i] <= 1e9
Time Limit: 1 sec
Sample Input 1:
2
3
0 1
1 2 3
2
0 1
1 2
Sample Output 1:
2 1 3
2 1
Explanation Of Sample Input 1 :
Test 1:
When we reverse the elements between indices 0 and 1 we get the array as 2 1 3.
Test 2:
When we reverse the elements between indices 0 and 1 we get the array as 2 1.
Sample Input 2 :
2
5
0 3
21 6 46 36 10
10
9 9
21 2 17 39 48 41 44 23 22 7
Sample Output 2 :
36 46 6 21 10
21 2 17 39 48 41 44 23 22 7
*/
#
include
<
iostream
>
using
namespace
std
;
void
ReverseArrayBetween
(
int
array[],
int
size,
int
idx_l,
int
idx_r) {
if
(idx_l > idx_r) {
return
;
}
while
(idx_l < idx_r) {
int
temp = array[idx_l];
array[idx_l] = array[idx_r];
array[idx_r] = temp;
idx_l++;
idx_r--;
}
}
int
main
() {
int
t;
cin >> t;
for
(
int
test_case =
0
; test_case < t; test_case++) {
int
size, idx_l, idx_r;
cin >> size >> idx_l >> idx_r;
int
array[size];
for
(
int
i =
0
; i < size; i++) {
cin >> array[i];
}
ReverseArrayBetween
(array, size, idx_l, idx_r);
for
(
int
i =
0
; i < size; i++) {
cout << array[i] <<
"
"
;
}
cout << endl;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL