human
Can you provide a code to efficiently check if a string has all unique characters without using any additional data structure and the other steps required given the following:
Efficiently check if a string has all unique characters without using any additional data structure | Returns true if all characters of str are unique . Assumptions : ( 1 ) str contains only characters from ' a ' to ' z ' ( 2 ) integers are stored using 32 bits.
An integer to store presence / absence of 26 characters using its 32 bits.
If bit corresponding to current character is already set.
set bit in checker.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to efficiently check if a string has all unique characters without using any additional data structure and the other steps required.
 def areCharactersUnique ( s ) :
	checker = 0
	for i in range ( len ( s ) ) :
		val = ord ( s [ i ] ) - ord ( ' a ' )
		if ( checker & ( 1 << val ) ) > 0 :
			return False
		checker |= ( 1 << val )
	return True
s = " aaabbccdaa "
if areCharactersUnique ( s ) :
	print ( " Yes " )
else :
	print ( " No " )