Is Anagram

An anagram is a word formed by rearranging the letters of another word. The words “listen” and "sile…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

There Should be a test case like “code and codp”. When I first solved this problem I noticed that my program has issue for that type of input. But the submission showed that my code passed all the tests.

1 Like


However, the solution provided by Toph seems to be working correctly on uDebug.

I know. The correct solution will print “No” in that case. What I’m saying is If I have a problem in my code that can’t print “No” in the specified case, and then If I submit my code, toph accepts my code and says "all test cases passed ". I hope you got what I’m trying to say.

1 Like

For these kind of situations, you should mention the Mods.
like @hjr265

1 Like

Thank you @Galib.603386 for pointing this out. The dataset didn’t really have any equal length strings in them that were not anagrams.

A new test case has been added.

It seems both of your recent submissions for this problem now fail. However, we usually do not update the verdict of a submission that has already been accepted (as a sort of extension of the similar ICPC rule).

You can retry the problem and try to solve it again.

1 Like
#include<stdio.h>
#include<string.h>
int main()
{
    char a[100],b[100];
    int c,d;
    scanf("%s",&a);
    scanf("%s",&b);
    c=strlen(a);
    d=strlen(b);
    if(c==d)printf("Yes");
    else printf("No");
    return 0;
}

I got wrong answer at 7th test case… I really don’t know what’s the problem in this code… Please help me to understand…,

Thank You

You are only comparing if the strings are equal in length. You are not checking if they are anagrams.

2 Likes

Would you please help me how to check it?

@Galib.603386 I have added this input in uDebug.

1 Like

It’s great that you are really checking what I’m saying. As you told, now I got stuck in the problem. :smile: I don’t get it. For which input my solution fails? Can you please tell me what’s wrong in my code?

#include<stdio.h>
#include<string.h>
int main()
{
    char a[100],b[100];
    scanf("%s",a);
    scanf("%s",b);
    int L1=strlen(a);
    int L2=strlen(b);
    int i,j,n=0;

    if(L1==L2){
        for(j=0;j<L1;j++){
            for(i=0;i<L1;i++){
                if(a[j]==b[i]){
                    b[i]=0;
                    n++;
                }
            }
        }
        if(n==L1){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
    else{
        printf("No\n");
    }
    return 0;
}

The code you submitted last and the code you have here are different.

This one looks correct to me.

1 Like

But using this code, I get wrong answer in the test case 7. Can you help me?

The checked your latest submission again, the code is different from this one. :slight_smile:

1 Like

Yeah, i get it now. Passed all tests in the submission.

1 Like

@hjr265 @touhidur
A = input(“”)
B = input(“”)
A = len(A)
B = len(B)
if A != B:
print(“No”)
else:
print(“Yes”)


What is the problem in this code?

You are merely checking if the length of both strings is equal or not.
READ THE PROBLEM STATEMENT CAREFULLY and try again.

@touhidur
I found the mistake and i have been solved the problem

1 Like
x = input()
y = input()
sum = 0
for i in range(127):
	sum += (x.count(chr(i)) - y.count(chr(i)))
if sum == 0:
	print("Yes")
else:
	print("No")

What’s the problem?

Everything I think :expressionless:.
Why are you calcuting the numerical difference between the ASCII values of the characters here?