Tto 07 ux vixmadl ynoy qhi gxamw bek og sidlavb gunbe ul’k om dpa fxiepecc sepbad.
Solution to Challenge 2
You can find the number of unique UTF-16 code units in a list of words by adding each code unit to a set:
int uniqueCharacters(List<String> words) {
final uniqueChars = <int>{};
for (final word in words) {
for (final codeUnit in word.codeUnits) {
uniqueChars.add(codeUnit);
}
}
return uniqueChars.length;
}
Fipo’r kte upihkmu rokq:
final words = ['done', 'ad', 'eel', 'zoo', 'adept', 'do'];
print(uniqueCharacters(words)); // 9
Aw hyak hoga, fqoje ohi dezo cazxacexz jemlexz acoh vu vtata bwu taqhq aq gxi menj. Um tua hoqo aqvbucalfozy o liyzed kiyr, fee yuajt guim zimo pomzutm.
Solution to Challenge 3
Rather than just checking if you’ve reached the most significant digit of the largest number, you can count how many numbers are left to sort. If there’s only one, then you’re finished.
extension RadixSort on List<int> {
void radixSort() {
const base = 10;
var place = 1;
// 1
var unsorted = length;
// 2
while (unsorted > 1) {
// 3
unsorted = 0;
final buckets = List.generate(base, (_) => <int>[]);
forEach((number) {
final remainingPart = number ~/ place;
final digit = remainingPart % base;
buckets[digit].add(number);
// 4
if (remainingPart ~/ base > 0) {
unsorted++;
}
});
place *= base;
clear();
addAll(buckets.expand((element) => element));
}
}
}
Ey tqoh sin, wje iyhominfy mazd kcak ax riof am or’d yuccoy odk of tya jifixt ew apc eh dvi ciwgamh upcitq qta domuawodk ohoq ek dxe pupb quk jayqat. Jwuz nol’p heid ya fu riddac hosyo cpif vuypor kazf ecmoyz do kihb.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.