Question: C# 1. Given a string, count the number of unique characters in the string. Null and empty strings both count as zero unique characters. You
C#
1. Given a string, count the number of unique characters in the string. Null and empty strings both count as zero unique characters. You can determine the length of this Boolean array with char.MaxValue + 1. Thus, you can create a Boolean array with a length of char.MaxValue + 1 to tag each character in a string. As char is compatible with int, you will need to use each char from the string as an index to this Boolean array, hence incrementing the counter when a new character is first seen, while iterating through all the characters in a string.
public int CountUniqueCharacters(string str) {
2. Sort an array of strings from the least to the greatest number of unique characters. The sorting of the strings with the same number of unique characters will remain unchanged. You may use any sorting algorithm youve desire, but do not use a built-in sorting method. You must also treat null strings and arrays.
public void SortByUniqueCharCount(string[] a) {
3. Sort an array of strings from the least to the greatest number of unique characters. Then, if there are multiple strings with the same number of unique characters, then sort by the string value using string's CompareTo function. You may use any sorting algorithm youve desire, but do not use a built-in sorting method. You must also treat null strings and arrays. Please note that null always comes before an empty string "".
public void SortByUniqueCharCountThenByString(string[] a) {
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
