Geeks-for-Geeks | Practice Problem | Problem Solution
11th October 2024
Problem : Reorganize The Array using Java using Java
Level : Easy
Language : Java
Topics Tags : Arrays | 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 of elements arr[] with indices ranging from 0 to arr.size() - 1, your task is to write a program that rearranges the elements of the array such that arr[i] = i. If an element i is not present in the array, -1 should be placed at the corresponding index.
Examples:
Input: arr[] = [-1, -1, 6, 1, 9, 3, 2, -1, 4, -1]
Output: [-1, 1, 2, 3, 4, -1, 6, -1, -1, 9]
Explanation: Here We can see there are 10 elements. So, the sorted array will look like [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] but in our array we are not having 0, 5, 7 and 8. So, at there places we will be printing -1 and otherplaces will be having elements.
Input: arr[] = [2, 0, 1]
Output: [0, 1, 2]
Explanation: Here We can see all the elements are present so no -1 is returned in array.
Expected Time Complexity: O(n).
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 | #gfgsolution | #gfgproblem | #recognizethearrayusingjava
Информация по комментариям в разработке