TGViewer
Coding Projects Coding Projects @programming_experts · 67.9K subscribers
Post #2795 2.11K
Time Complexity: O(n + m)

Space Complexity: O(n + m)

1️⃣8️⃣9️⃣ How Do You Check if Two Strings are Anagrams?

Answer:

Two strings are anagrams if they contain the same characters with the same frequencies, but possibly in a different order.

Example:

"listen" → "silent"

Both contain the same characters, so they are anagrams.

Python:

str1 = "listen"
str2 = "silent"

if sorted(str1) == sorted(str2):
print("Anagrams")
else:
print("Not Anagrams")


Time Complexity: O(n log n)

A frequency-count approach can achieve O(n) average time.

1️⃣9️⃣0️⃣ How Do You Find the First Non-Repeating Character?

Answer:

Count the frequency of every character, then scan the string again and return the first character whose frequency is "1".

Example:

Input: "swiss"

Output: "w"

Python:

from collections import Counter

text = "swiss"
count = Counter(text)

for char in text:
if count[char] == 1:
print(char)
break


Time Complexity: O(n)

Space Complexity: O(k), where "k" is the number of distinct characters.

🔥 Double Tap ❤️ For Part-20
  • ❤ 8
  • 🔥 1
More from @programming_experts
  1. Sep 29, 2026Post #2901
  2. Sep 29, 2026Post #2900
  3. Sep 29, 2026Post #2899
  4. Sep 29, 2026What will be the output? x = 10 if x > 5 and x < 10: print("Yes") else: print("No") A) Yes…
  5. Sep 29, 2026Post #2897
  6. Sep 29, 2026𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗟𝗲𝗮𝗿𝗻 𝗔𝗜 𝗶𝗻 𝟮𝟬𝟮𝟲🚀 ​ Explore 6 free resource…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →