← Valid Anagram
Discussions
Sign in to join the discussion.
A
aksharakulkarni
OFFICIAL
2 months ago
Why does my solution TLE on the last test case?
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 0 replies
K
kavyanaidu
OFFICIAL
3 months ago
Why does my solution TLE on the last test case?
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 3 replies
N
neha_75
OFFICIAL
4 months ago
Clean Java solution, beats most submissions.
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 1 reply
K
kavyanaidu
2 months, 1 week ago
Finally got AC after 3 WAs. Sharing what I missed.
Use a hash map from value to index (or count). For each element check whether its complement is already in the map, then insert it. That makes it O(n) instead of the O(n²) brute force.
💬 1 reply