Pregunta de entrevista

Entrevista para Member of Technical Staff Software Engineer

-Palo Alto, CA

VMware

Given a series of strings, find the biggest common prefix.

Etiquetas:string logic
RespuestaAgregar etiquetas

Respuestas de entrevistas

4 respuestas

2

What? Prefix is not started from the very first string? Jesus I cannot read Eng!

Jun Zheng en

0

x = ["Ravite", "Raviteja", "Ravby", "Raviejaain","Ravi" ] #Given String y = x[0] for i in x: if len(i)> len(y): y = i fin = [] y = list(y) for i in range(len(y)): count = 0 for j in range(len(x)): if y[i]==x[j][i]: count +=1 if count == len(x): fin.append(y[i]) else: break if len(fin) > 0: print "".join(fin) else: print "No common prefix in series"

Raviteja Ainampudi en

1

/** * Jun Zheng, Rice Univ * Given a series of strings, find the biggest common prefix. * Real question of VMware * Java7; running time: O(n^2) * @param str * @return */ private String biggestPrefix(String[] strs){ String prefix=strs[0]; for(int i=1;i0;i++){ int j; for(j=0;j0)? prefix:"No such prefix!"; }

Jun Zheng en

0

How that works? You are considering "prefix" must come from the very first string, which is not true. In the following string set, the biggest common prefix is "xyzasd" - which this program fails to find! String[] arr = {"MxyzasdNmm", "kxyzasdDodal", "I am a Good Boy", "JadxyznasdM Golmal", "ABCDEF", "ABCDEFGH", "Sunnyvale", "CaliforniaKxyzaszzMon"};

Java User en

Agregar respuestas o comentarios

Para comentar esto, Inicia sesión o regístrate.