Solved HackerRank challenge with Python's defaultdict

I just solved another HackerRank challenge that tested my understanding of Python’s collections module, specifically the defaultdict container. In this challenge, we’re given two groups of words. - Group A can have repeating words. - Group B contains query words. For each word in Group B, we have to print all positions (1-based indices) where it appears in Group A — or -1 if it doesn’t appear. Using defaultdict(list) made it clean and efficient to store multiple positions for each word without worrying about key errors. Here’s the output from my program: Input: 5 2 a a b a b a b Output: 1 2 4 3 5 This challenge helped reinforce how Python’s data structures can make code both readable and powerful. Check out the full code and more of my HackerRank solutions on my GitHub: https://lnkd.in/dgsj_mpP #Python #HackerRank #Coding #SoftwareDevelopment #defaultdict #collections #Learning

To view or add a comment, sign in

Explore content categories