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. Algorithms
  3. Strings
  4. Making Anagrams
  5. Discussions

Making Anagrams

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

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

  • anirudherabelly
    7 years ago+ 20 comments

    Java implementation of the problem!!

    import java.io.*;

    import java.util.*;

    import java.text.*;

    import java.math.*;

    import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc=new Scanner(System.in);
        String s1=sc.nextLine();
        String s2=sc.nextLine();
        int cArr[]=new int[26];
        int cArr1[]=new int[26];
        for(int i=0;i<s1.length();i++)cArr[s1.charAt(i)-97]++;
        for(int i=0;i<s2.length();i++)cArr1[s2.charAt(i)-97]++;
        int count=0;
        for(int i=0;i<26;i++)count+=Math.abs(cArr[i]-cArr1[i]);
        System.out.println(count);
    }
    

    }

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