diff --git a/coding_freshmen/C/Sarthak/Anagram.md b/coding_freshmen/C/Sarthak/Anagram.md new file mode 100644 index 0000000..56c814a --- /dev/null +++ b/coding_freshmen/C/Sarthak/Anagram.md @@ -0,0 +1,19 @@ +# +Anagram + +# Problem Explanation 🚀 +An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. + +# Your logic 🤯 +* Approach: Created two arrays to hold the string and compared the array one by one +* Own test cases if any +* Code Structure and Libraries used + +# Time Complexity and Space Complexity +```cpp +Example + +Time Complexity -> O(n^2) +Space Complexity -> O(1) + +``` diff --git a/coding_freshmen/C/Sarthak/anagram.c b/coding_freshmen/C/Sarthak/anagram.c new file mode 100644 index 0000000..43764c8 --- /dev/null +++ b/coding_freshmen/C/Sarthak/anagram.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <string.h> + +int main() +{ + char s[100], t[100]; + printf("Enter 1st string: "); + gets(s); + printf("Enter 2nd string: "); + gets(t); + int n = 0; + int len_s = strlen(s); + int len_t = strlen(t); + for (int i = 0; i < len_s; i++) + { + for (int j = 0; j < len_t; j++) + { + if (s[i] == t[j]) + { + n++; + } + } + } + + if (n == len_s) + { + printf("True"); + } + else + { + printf("False"); + } + + return 0; +}