You are given an array of strings and you are asked to display all the anagrams within the array. For those who don’t know, two words are anagrams if they contain the same characters.
Sort every string in the array(can be done fast with radix-sort) then while doing that for each string store in a hash-table the original and the sorted one, when you encounter a string that's already in the hash-table print these pair of anagrams.
oops, didn't notice you will have duplicate prints, so instead of printing the pair you can add the current anagram to the hash-table slot where the sorted version appears. at the end print everything.
You are given n real numbers in an array. A number in the array is called a decimal dominant if it occurs more than n/10 times in the array. Give an O(n) time algorithm to determine if the given array has a decimal dominant.
Implement a function getbits, that returns the(right adjusted) n bits that begin at position p of an integer. Assume bit position 0 is at the right end and that n and p are sensible positive values.
Sort every string in the array(can be done fast with radix-sort) then while doing that for each string store in a hash-table the original and the sorted one, when you encounter a string that's already in the hash-table print these pair of anagrams.
ReplyDeleteoops, didn't notice you will have duplicate prints, so instead of printing the pair you can add the current anagram to the hash-table slot where the sorted version appears. at the end print everything.
ReplyDelete