Shil and Lucky String
Practice
3.7 (68 votes)
Algorithms
Approved
Easy
Implementation
Open
Sorting
Problem
86% Success 8131 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Shil is your new boss and he likes lucky strings very much. A string is called lucky if and only if each character from first half of the string can be paired to each character from second half of the string. AND:

  1. In each pair, a character from the first half is strictly greater than a character from the second half OR
  2. In each pair, a character from the first half is strictly lesser than a character from the second half OR
  3. In each pair, a character from the first half is equal to character from the second half.

Each character should be used exactly once in pairing.

Your are given a string S. You want to change the minimum number of characters to make this string lucky so that you can gift it to your boss.

Note that each character in lucky string should be in lower case alphabet ( 'a' - 'z' ).

Input format:
The first line consists of an integer N. The second line consists of N lower case characters.

Output format:
Print minimum number of changes required to make given string lucky.

Constraints:
1 < N ≤ 105
N will be an even integer.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
15 votes
Tags:
AlgorithmsEasyMerge sortSorting
Points:20
7 votes
Tags:
Merge SortSortingAlgorithmsGreedy Algorithms
Points:20
172 votes
Tags:
ApprovedEasySorting