We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Arrays
- Arrays - DS
- Discussions
Arrays - DS
Arrays - DS
Sort by
recency
|
2192 Discussions
|
Please Login in order to post a comment
This problem is a simple exercise in reversing an array of integers. The function should take an array as input and return the array in reversed order. It helps practice basic array manipulation and indexing concepts. गोल्ड 365
include
using namespace std;
void reverse(int arr[], int n) { // Change return type to void int start = 0; int end = n - 1; int temp; while (start < end) { temp = arr[start]; arr[start] = arr[end]; arr[end] = temp; start++; end--; } }
int main() { int arr[] = {2, 3, 4, 5, 6, 7, 8}; int n = sizeof(arr) / sizeof(arr[0]);
}
My Java soluton with o(n) time complexity and o(1) space complexity: