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.
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
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