Solved LeetCode #697: Degree of an Array in Java with HashMap

🚀 𝘿𝙖𝙮 98 𝙤𝙛 100 𝘿𝙖𝙮𝙨 - 𝙅𝙖𝙫𝙖  ✅problem : Degree of an Array(Question No:697) 📍platform: LeetCode 🔍Level: Easy. ✅ LeetCode Problem: Degree of an Array (#697) Successfully solved with a runtime of 10 ms (Beats 93.22%) 🎯 🔍 Approach: Used a HashMap to track each number’s ➤ First occurrence index ➤ Last occurrence index ➤ Frequency count Calculated the degree (maximum frequency) of the array. Found the shortest subarray that has the same degree. 💡 Key Insight: By storing indices and counts efficiently, we can compute the shortest subarray in O(n) time — a neat combination of map tracking and logic optimization. #LeetCode #Java #CodingChallenge #ProblemSolving #DataStructures #Algorithms #LearningJourney #HashMap #Programming #CodeNewbie #WomenInTech

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories