Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.hackerrank.com/challenges/ctci-making-anagrams
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- class Solution {
- static void Main(String[] args) {
- string a = Console.ReadLine();
- string b = Console.ReadLine();
- int aSize = a.Length;
- int bSize = b.Length;
- //a = 97, z = 122
- int[] abcFirst = new int[26];
- int[] abcSecond = new int[26];
- //a -> 0, z -> 25
- //x-97
- for(int i = 0; i < 26; i++){
- abcFirst[i] = 0;
- abcSecond[i] = 0;
- }
- for(int i = 0; i < aSize; i++){
- abcFirst[a[i]-97]++;
- }
- for(int i = 0; i < bSize; i++){
- abcSecond[b[i]-97]++;
- }
- int deletedNumbers = 0;
- for(int i = 0; i < 26; i++){
- if((abcFirst[i] - abcSecond[i]) != 0){
- deletedNumbers += Math.Abs(abcFirst[i] - abcSecond[i]);
- }
- }
- Console.WriteLine(deletedNumbers);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment