From 544736d977814aadacbc5042b0f6e352c2e8116a Mon Sep 17 00:00:00 2001 From: chetanraj7 <111502248+chetanraj7@users.noreply.github.com> Date: Mon, 10 Oct 2022 21:22:45 +0530 Subject: [PATCH] Create GamewithNos.cpp This is very good problem on gfg. I added optimized C++ code for that. Please accept my PR with hacktoberfest-accepted label. --- Leetcode-Easy/GamewithNos.cpp | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Leetcode-Easy/GamewithNos.cpp diff --git a/Leetcode-Easy/GamewithNos.cpp b/Leetcode-Easy/GamewithNos.cpp new file mode 100644 index 0000000..9fc2dd7 --- /dev/null +++ b/Leetcode-Easy/GamewithNos.cpp @@ -0,0 +1,46 @@ +//{ Driver Code Starts +#include +using namespace std; + + +int* game_with_number(int arr[], int n); + +int main() +{ + + int t;cin>> t; + while(t--) + { + int n; + cin >> n; + int arr[n]; + + for(int i=0;i>arr[i]; + + int *arr2; + + arr2 = game_with_number(arr, n); + for(int i = 0;i < n; i++) + cout << arr2[i] << " "; + + cout << endl; + + } + +} + +// } Driver Code Ends + + +int* game_with_number(int arr[], int n) +{ + + for(int d=0;d < n-1;d++) + { + arr[d] = arr[d]^arr[d+1]; + } + + return arr; + +}