Check if a string has all unique characters

This problem asks us to write a function that takes in a string and returns True if the string has all unique characters, and False if it does not.

Problem

Implement an algorithm to determine if a string has all unique characters.
Input: "abcdefg"
Output: True
Input: "abcdefghijklmnopqrstuvwxyz"
Output: False

Solution

This solution is in C#. Our A.I. can create solutions in multiple languages.
by kayakane
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = "abcdefghijklmnopqrstuvwxyz";
            Console.WriteLine(IsUnique(input));
            Console.ReadLine();
        }

        static bool IsUnique(string input)
        {
            //This solution is optimal because it uses a HashSet to store the characters.
            //The HashSet will not allow duplicates, so if the length of the HashSet is less than the length of the input string,
            //then there are duplicates.
            HashSet<char> set = new HashSet<char>();
            foreach (char c in input)
            {
                set.Add(c);
            }
            return set.Count == input.Length;
        }
    }
}

A.I. Evaluation of the Solution

The candidate's solution is correct and uses a HashSet to store the characters, which is an efficient way to check for duplicates.

Evaluated at: 2022-11-20 16:15:44