Questions tagged [anagram]

A word, phrase, or name formed by rearranging the letters of another, such as cinema, formed from iceman.

470 questions
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,763
  • 2
  • 21
  • 39
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
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…
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
  • 55,232
  • 47
  • 119
  • 176
5
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
  • 61
  • 1
  • 5
4
votes
2 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
  • 63
  • 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
  • 2,527
  • 4
  • 23
  • 27
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
  • 11,896
  • 23
  • 73
  • 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
  • 4,809
  • 23
  • 53
  • 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
  • 85
  • 4
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
  • 1
4
votes
7 answers

Find group of strings that are anagrams

This question refers to this problem on lintcode. I have a working solution, but it takes too long for the huge testcase. I am wondering how can it be improved? Maybe I can decrease the number of comparisons I make in the outer loop. class…
Wajahat
  • 1,545
  • 3
  • 19
  • 44
4
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
  • 71
  • 5
4
votes
3 answers

String permutations using recursion in Java

I came across THIS post which tried very hard to explain the recursive solution to print all string. public class Main { private static void permutation(String prefix, String str) { int n = str.length(); if (n == 0) …
Walt
  • 1,267
  • 2
  • 14
  • 28
4
votes
5 answers

Java Anagram Solver

I can work out how to create anagrams of a string but I don't know how I can compare them to a dictionary of real words to check if the anagram is a real word. Is there a class in the Java API that contains the entire English dictionary?
Alex
  • 4,609
  • 9
  • 43
  • 65
1 2
3
31 32