Skip to content

feat(anagram): add C solution (#68) - #69

Open
aadiitya2007 wants to merge 1 commit into
techcsispit:mainfrom
aadiitya2007:feat/anagram-c-solution
Open

aadiitya2007 wants to merge 1 commit into
techcsispit:mainfrom
aadiitya2007:feat/anagram-c-solution

Conversation

@aadiitya2007

Copy link
Copy Markdown
Contributor

Closes #68

What I changed

Added an efficient C implementation in problems/anagram/solution.c using a 26-element character frequency array.

How it works

The problem requires checking whether two input words or phrases separated by a comma are anagrams of each other, ignoring capital letters and whitespace.

The implementation reads the line from standard input via fgets and finds the comma delimiter using strchr. It tracks character frequencies using a fixed 26-element array count[26]. For the first phrase (before the comma), it increments the count for alphabetic characters (tolower(c) - 'a'). For the second phrase (after the comma), it decrements the counts. Finally, it checks that all counts return to zero in $O(n)$ time and $O(1)$ auxiliary space, printing true if anagrams, otherwise false.

Verification

Ran the test runner using python3 run.py anagram --lang c:

  • solution.c: ok (0.434s)
    Summary: 1 passed, 0 failed, 0 skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(anagram): add C solution

1 participant