Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6705455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:24:21+00:00 2026-05-26T07:24:21+00:00

I am sure this question has been discussed in the distant past several times

  • 0

I am sure this question has been discussed in the distant past several times on Stack Overflow. I am just trying to verify whether my answer is valid or not. I saw this question in this thread. I am sorry that this post is a duplicate of the thread and if it has to be removed, I shall do it.


I thought of doing this in a much more simple way. By just XORing the characters in the string.

So O(n) for XORing each character and O(1) for comparison of last characters in both the strings which gives a O(n) solution.

Even though the last characters may be any special symbol but if the strings are anagrams they still end up being the same. Am I right in this logic?

So instead of doing all sorting and hashing can this solution be adopted? My code goes like this:

char a[7] = "Length";
char b[7] = "enghtL";

for (int i = 1; i < 6; i++) {
   a[i] = a[i] ^ a[i-1];
   b[i] = b[i] ^ b[i-1];
}

if (a[5] == b[5]) {
   cout << "\n The strings are anagrams";
}
else {
   cout << "\n No they are not";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:24:22+00:00Added an answer on May 26, 2026 at 7:24 am

    I’m sorry but this won’t work.

    Sure, if it is an anagram, the code (if it works correctly) will say so but you will also have a lot of ‘false positives’ because several (different) strings can yield the same output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm sure this question has been answered 100 times, I just can't figure out
Halo I'm sure this question has been asked many times in the past, but
I am quite sure this question has already been asked several times and I
I'm sure this question has been asked a thousand times but after an hour
I'm sure this question has been asked many times, but I can't figure this
I'm sure this question has been asked many times. I believe I know the
I'm sure this question has been asked but it's hard to just google specifically
I'm sure this has been discussed many times before, but for whatever reason I
I'm sure this question has been asked a million times, however I haven't been
I'm pretty sure that this question already has been answered somewhere. It just seems

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.