We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Java
  3. Strings
  4. Java Anagrams
  5. Discussions

Java Anagrams

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • shubh997
    7 years ago+ 24 comments

    It was a damn simple problem you can solve it by sorting both the arrays(by taking character arrays) and checking if they are equal

    static boolean isAnagram(String A, String B) { char a[]=A.toLowerCase().toCharArray(); char b[]=B.toLowerCase().toCharArray();

       Arrays.sort(a);
       Arrays.sort(b);
    
       return Arrays.equals(a,b);
    

    }

    67|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature