Question DSA-STR-0048
MediumHow can you check whether two strings of length n are anagrams in O(n) time?
- A.
Sort both and compare (O(n) always)
- B.
Compare them character by character
- C.
Sign up free to see the answer and a step-by-step explanation.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Strings question
How can you check whether two strings of length n are anagrams in O(n) time?
Sort both and compare (O(n) always)
Compare them character by character
Sign up free to see the answer and a step-by-step explanation.
Reverse one and compare
Count the characters of each with an array or hash map and compare the counts