Dropbox Interview Question
12 Interview Reviews |
Back to all Dropbox Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at Dropbox:
given a number as a string write a algorithm to map to its oral description. I.e. "1" -> "11" //this can be thought of as there is one one. "11" -> "21" // there are two ones "21" -> "1211" // there is one two and one one "1211" -> "111221" ect. //there is one one, one two and two ones
| Tags: | algorithm See more , See less 8 |
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (3)
1 of 3 people found this helpful
def oralDescription(string):
firstchar = string[0]
count = 0
all = ""
for i in range(0, len(string), 2):
print "There are", string[i], "of", string[i+1]
oralDescription("112111")
Helpful Answer?
Yes |
No
Inappropriate?
f = string[0]
for i in range(0, len(string)):
if string[i] == f:
count = 1
if i == len(string)-1:
sys.stdout.write("%d%s" %(count, f))
break
while (string[i+1] == string[i]):
count += 1
i += 1
if (i+1) >= len(string):
break
sys.stdout.write("%d%s" %(count, f))
if (i+1) >= len(string):
break
f = string[i+1]
print ""
I might have some extra unnecessary code and could definitely clean this up a little, but it's a working version.
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 1 people found this helpful
by Interview Candidate:
String output = "";
char prev = input.charAt(0);
int count = 0;
for(int i = 0; i < input.length(); i++){
char cur = input.charAt(i);
if(cur == prev)
count++;
else {
output += count + "" + prev;
count = 1;
}
prev = cur;
if(i + 1 >= input.length())
output += count + "" + cur;
}
return output;
}