A word, phrase, or name formed by rearranging the letters of another, such as cinema, formed from iceman.
Questions tagged [anagram]
531 questions
6
votes
4 answers
Check my anagram code from a job interview in the past
Had the following as an interview question a while ago and choked so bad on basic syntax that I failed to advance (once the adrenalin kicks in, coding goes out the window.)
Given a list of string, return a list of sets of strings that are anagrams…

Michael Dorgan
- 12,453
- 3
- 31
- 61
6
votes
4 answers
Fast anagram solving
Given two strings, I would like to determine whether or not they are anagrams of one another. Here is the solution that I came up with:
# output messages
def anagram
puts "Anagram!"
exit
end
def not_anagram
puts "Not an anagram!"
…

Hunter McMillen
- 59,865
- 24
- 119
- 170
6
votes
2 answers
Regex - find anagrams and sub-anagrams
I have a pool of characters and I want to match all the words which are anagrams of those chars or of a subset of those chars using a regular expression.
Example: given the string "ACNE" the regex should give me these results:
ACNE [T]
CENA …

HghlnDR
- 71
- 1
- 1
- 5
5
votes
3 answers
Array of Strings contains only anagrams?
I have been given an exercise about anagrams and it looked so really easy that I have a doubt I am missing something.
The solution I implemented is the one I will present shortly, and I wanted to ask you if you could think of any optimization,…

mdm
- 3,928
- 3
- 27
- 43
5
votes
2 answers
Finding anagrams in a word list
I have a word list and a file containing a number of anagrams. These anagrams are words found in the word list. I need to develop an algorithm to find the matching words and produce them in an output file. The code I have developed so far has only…
user808066
5
votes
2 answers
Efficient way to find anagrams of sentences from dictionary?
I need to make a program that takes a file with a dictionary and an arbitrary string as an input and then outputs all combinations of words from that dictionary that make up anagrams of the given string.
For example, using the 100 most popular words…

Mashallah
- 81
- 5
5
votes
7 answers
clustering words based on their char set
Say there is a word set and I would like to clustering them based on their char bag (multiset). For example
{tea, eat, abba, aabb, hello}
will be clustered into
{{tea, eat}, {abba, aabb}, {hello}}.
abba and aabb are clustered together…

user2671488
- 93
- 5
5
votes
5 answers
Algorithm to find longest anagram
Let's say that we have a dictionary of about 250.000 words. Algorithm should take in 12 letters as an array or a string and find the variation that matches longest word from a dictionary.
Of course, one can always brute-force it, but I wonder what…

Milan Babuškov
- 59,775
- 49
- 126
- 179
4
votes
3 answers
Java anagram finder algorithm
I have an array of Strings in Java. I need to find anagrams from the array and print them to the screen.
I am having difficulty with the part where I am supposed to compare array elements to check if they're anagrams or not. How would I do this? I…

cdn
- 61
- 1
- 1
- 5
4
votes
7 answers
Finding and grouping anagrams by Python
input: ['abc', 'cab', 'cafe', 'face', 'goo']
output: [['abc', 'cab'], ['cafe', 'face'], ['goo']]
The problem is simple: it groups by anagrams. The order doesn't matter.
Of course, I can do this by C++ (that's my mother tongue). But, I'm wondering…

Nullptr
- 3,103
- 4
- 27
- 28
4
votes
12 answers
Find if 2 strings are anagram in O(1) space and O(n) time
You can find if 2 strings are anagrams after sorting both strings in O(nlogn) time, however is it possible to find it in o(n) time and O(1) space.

shreyasva
- 13,126
- 25
- 78
- 101
4
votes
1 answer
How do I create a list of all possible anagrams of a word in javascript?
How do I create a list of all possible anagrams of a word in javascript?If this question has already been asked please direct me to the answer?
Thank You

manraj82
- 5,929
- 24
- 56
- 83
4
votes
3 answers
Is there a class in Java which keeps duplicates but not order of data?
I am dealing with anagrams so I'm concerned only with the characters present in the string but not their order.
I searched for a suitable Collection class but in vain.
Can you please suggest any class that could help me to
keep duplicates but…

Sriman
- 87
- 1
- 5
4
votes
1 answer
How to optimize finding anagrams from a text file in Go
I am trying to solve a coding challenge where one must print all anagrams from a text file matching the input string. Program must execute as fast as possible. Working code:
package main
import (
"bufio"
"fmt"
"log"
"os"
"sort"
…

strom73
- 41
- 2
4
votes
2 answers
Efficient algorithm for phrase anagrams
What is an efficient way to produce phrase anagrams given a string?
The problem I am trying to solve
Assume you have a word list with n words. Given an input string, say, "peanutbutter", produce all phrase anagrams. Some contenders are: pea nut…

Ravi
- 501
- 2
- 4
- 7