Pergunta de entrevista da empresa Yelp

Main Technical Question: Write a function that takes as input an array of words input => ['cat', 'star', 'act', 'god', 'arts', 'dog', 'rats'] and returns a sorted array output => ['cat', 'act', 'god', 'dog', 'start', 'arts', 'rats']

Respostas da entrevista

Sigiloso

24 de out. de 2013

Follow senthill comment, I think they need another step of sorting based on the length. words = ['cat', 'star', 'act', 'god', 'arts', 'dog', 'rats'] words = sorted(words,key=lambda x:sorted(x)) sorted(words, key=lambda x:len(x))

3

Sigiloso

7 de out. de 2013

Below is a pythonic implementation of the same, assumption is we are allowed to built-in sorted method. words = ['cat', 'star', 'act', 'god', 'arts', 'dog', 'rats'] print sorted(words,key=lambda x:sorted(x))

2

Sigiloso

7 de out. de 2013

Below is a pythonic implementation of the same, assumption is we are allowed to built-in sorted method. words = ['cat', 'star', 'act', 'god', 'arts', 'dog', 'rats'] print sorted(words,key=lambda x:sorted(x))

1

Sigiloso

3 de abr. de 2015

import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Iterator; import java.util.Set; public class Anagrams_Yelp { public Anagrams_Yelp() { String[] words = {"masterschool","cat", "star", "act", "god", "arts", "dog", "rats","schoolmaster"}; printAnagramsTogether(words); } private void printAnagramsTogether(String[] words) { ArrayList finalList = new ArrayList(); HashMap> map = new HashMap>(); for (int i = 0; i list = map.get(myString); list.add(str); map.put(myString, list); }else{ ArrayList list = new ArrayList(); list.add(str); map.put(myString, list); } } Set keySet = map.keySet(); Iterator objIterator = keySet.iterator(); while(objIterator.hasNext()){ ArrayList list = map.get(objIterator.next()); finalList.addAll(list); } int i = 0; while(i

Sigiloso

26 de out. de 2013

public static void insertionSort(String[] arr) { for(int i=1;i arr[j+1].length()) { String temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } return arr; }

2

Sigiloso

20 de set. de 2013

http://stackoverflow.com/questions/15045640/how-to-check-if-two-words-are-anagrams-in-java