Rotate and delete using Java | 02 Oct 2024 | GFG POTD | Array | Data Structure | Practice

Rotate and delete using Java | 02 Oct 2024 | GFG POTD | Array | Data Structure | Practice

Geeks-for-Geeks | Practice Problem | Problem Solution 02nd October 2024 Problem : Rotate and delete using Java Level : Medium Language : Java Topics Tags : Arrays | Algorithms | Data Structure ----------------------------------------------------------------------------- ⬇️ You may also visit my another playlists : 👉 LeetCode Problems :    • LeetCode Problems   👉 Code360 by coding ninja's mcq solution :    • Coding Ninjas | MCQ Daily Solution | Pract...   👉 Geeks-for-Geeks :    • Geeks-for-Geeks Problems   ---------------------------------------------------------- ➡️ Problem Statement : Given an array arr integers. Do the following operation until a single element is left. For every kth operation: Right, rotate the vector clockwise by 1. Delete the (n – k + 1)th element from the last. Now, Return the element that is left in the end. Examples: Input: arr = [1, 2, 3, 4, 5, 6] Output: 3 Explanation: Rotate the array clockwise i.e. after rotation the array A = {6, 1, 2, 3, 4, 5} and delete the last element that is {5} that will be A = {6, 1, 2, 3, 4}. Again rotate the array for the second time and deletes the second last element that is {2} that will be A = {4, 6, 1, 3}, doing similar operation when we perform 4th operation, 4th last element does not exist. Then we deletes 1st element ie {1} that will be A = {3, 6}. So, continuing this procedure the last element in A is {3}. So, the output will be 3. Input: arr = [1, 2, 3, 4] Output: 2 Explanation: Rotate the vector clockwise i.e. after rotation the vector arr = [4, 1, 2, 3] and delete the last element that is 3 that will be arr = [4, 1, 2]. After doing all the operations, the output will be 2. Expected Time Complexity: O(n2) Expected Auxiliary Space: O(1) ------------------------------------------------------ Stay connected with me on social media for more updates and behind-the-scenes content ! You can find me on 🔍: 📱 Instagram Profile :   / _ganesh_p09   🌐 LinkedIn Profile :   / ganesh-prasad09   -------------------------------------------------------------- 🔔 If you enjoyed the content, please subscribe to the channel for more updates! 📺 👍 If you found this video helpful, don't forget to give it a thumbs up and share it with your friends! 📤 🙏 Thank you for watching the video! 😊 ---------------------------------------------------------------- #gfgproblemoftheday | #Rotateanddelete | #todaysolutionusingjava gfg | #gfgproblems