Write a method that takes in an input String and returns true if all the characters in the String are unique and false if there is even a single repeated character. The method should return true if the input is null or empty String.
Use an Array of booleans to keep track of the count of different characters in the input (256 possibilities for 8 bit characters). Index this array with the ASCII value of the character (between 0 and 255) to decide the uniqueness of the String.
Remember that an ASCII character is an 8 bit number, and its value ranges from 0 and 255. An array of 256 booleans provides an efficient buffer to keep a track of encountered characters. 1. If the input is null[Empty], return true. 2. Create an array of 256 booleans. boolean arr = new boolean 3. If you write int pos = str.charAt(i), the ith character of the string str will be cast to a number between 0 and 255 4. Run a for loop across the input String. Check the [0..255]th index in the boolean array. The index is the number obtained in the previous step. 5. If that position is false, mark it true. If it is true, it implies that you have encountered the character before and hence there is a repetition. Return false 6. At the end of the for loop, return true.