Skip to content

Instantly share code, notes, and snippets.

@janvichhabra
Created December 30, 2021 08:50
Show Gist options
  • Save janvichhabra/21f35ffd92ade646851bc5b518c4f72f to your computer and use it in GitHub Desktop.
Save janvichhabra/21f35ffd92ade646851bc5b518c4f72f to your computer and use it in GitHub Desktop.
Find Anagram Mappings
Q1. What is a Anagram?
Ans -> a word or phrase that is made by arranging the letters of another word or phrase in a different order.
Q2)What will we store in our pair class?
Ans: We will be required to use a pair class, which is going to store Integer and an ArrayList
Q3) What could be the best data structure for this problem?
Ans: HashMap, because here we have to see the frequency of every element and the best way to see frequency is frequency map.
Q4. What is the average Time Complexity to solve this question?
Ans: O(n), Since we have traversed the array(b) first and stored this element in our map.
Then again we are traversing our array(a). So the time complexity will be O(2n). So in the big O terms it is going to be O(n).
Q5. What is the average Space Complexity to solve this question?
Ans: O(n), The space complexity is linear due to the extra space utilized by our HashMap.
1. Can you think any approach by using a HashMap?
2. We will be required to use a pair class, which is going to store Integer and an ArrayList
3. traverse our array and check for the conditions.
1. Are Listen and silent anagrams of each other?
a. True
b. False
Answer: True
2. Are Triangle and angle anagrams of each other?
a. True
b. False
Answer: False
3. _______ can be used to find if any two given strings are anagrams or not.
a. Hashmap
b. Stacks
c. Trees
d. Graphs
Answer: HashMap
4. TreeMap is sorted by ______
a. keys
b. values
c. both
d. none of the above
Answer: keys
5. What are Anagrams?
a. a word or phrase that is made by arranging the letters of same word or phrase in a different order
b. a word or phrase that is made by arranging the letters of another word or phrase in a same order
c. a word or phrase that is made by arranging the letters of another word or phrase in a different order
d. None of the above
Ans -> c. a word or phrase that is made by arranging the letters of another word or phrase in a different order
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment