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

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Interview Preparation Kit
  3. String Manipulation
  4. Strings: Making Anagrams

Strings: Making Anagrams

Problem
Submissions
Leaderboard
Discussions
Editorial
Topics

A student is taking a cryptography class and has found anagrams to be very useful. Two strings are anagrams of each other if the first string's letters can be rearranged to form the second string. In other words, both strings must contain the same exact letters in the same exact frequency. For example, bacdc and dcbac are anagrams, but bacdc and dcbad are not.

The student decides on an encryption scheme that involves two large strings. The encryption is dependent on the minimum number of character deletions required to make the two strings anagrams. Determine this number.

Given two strings, and , that may or may not be of the same length, determine the minimum number of character deletions required to make and anagrams. Any characters can be deleted from either of the strings.

Example

Delete from and from so that the remaining strings are and which are anagrams. This takes character deletions.

Function Description

Complete the makeAnagram function in the editor below.

makeAnagram has the following parameter(s):

  • string a: a string
  • string b: another string

Returns

  • int: the minimum total characters that must be deleted

Input Format

The first line contains a single string, .
The second line contains a single string, .

Constraints

  • The strings and consist of lowercase English alphabetic letters, ascii[a-z].

Sample Input

cde
abc

Sample Output

4

Explanation

Delete the following characters from the strings make them anagrams:

  1. Remove d and e from cde to get c.
  2. Remove a and b from abc to get c.

It takes deletions to make both strings anagrams.

Author

amititkgp

Difficulty

Easy

Max Score

25

Submitted By

254378

Need Help?


View discussions
View editorial
View top submissions
RESOURCES

  • Strings: An Overview

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy