Community Page
- elliottback.com/wp/ Jump to website »
-
Subscribe -
Community
-
Top Commenters
-
Popular Threads
-
Recent Comments
- i want this work please reply me ....gibmel@ymail.com
- did you do at moto photo or the passport photo service???I am in need for canadian passport photo and I live near washington dc...
- Hi, Worked for years, but today requires a new activation.... serial number 1045 1557 0885 5951 0032 1070 Activation Code 7067 3221 8552 6937 3433 2427 0144 3945 Activation Type: Repair 93:13 Many...
- Hi Susan, My mother lives in Colorado Springs and is about to undergo the Canadian passport routine. Did you find a place in the Springs for Canadian passport pictures?
- PHOENIX, ARIZONA For anyone in the PHOENIX metropolitan area who is looking for Canadian passport photos, I urge you to go to Hassan Photography. They were recommended by the Canadian Consulate in...
4 years ago
It seems like you did a pretty good job on your interview. What groups were you interviewing with?
I've been an MS intern twice, and it's an experience that's worth every minute. Not to mention they pay well.
4 years ago
4 years ago
I've been following your site pretty closely--I have to admit it was more than a little inspiration for the new version of my site. I started with Kubrick and then modified it in all different directions.
I like how you're starting a blogging network--are you pulling your fellow students to be members of your editorial staff?
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
For each digit in the phone number
For each letter corresponding to that digit
recursively invoke
End
End
You need to swap in three different letter choices for each digit (there are 7, usually) in the input. If you pay attention to the bounds, you'll notice that only about 7! calls are made, too, because the number of calls decreases by 1 everytime.
3 years ago
3 years ago
First, kudos on using a recursive call - I'm sure if you did try to nest seven for loops they'd ask you to extend your code to a 100-digit number. I haven't compiled and run your code, but on inspection I see one enhancement and one bug/issue/problem. The enhancement is a performance one, which the compiler may do for you, but to make it explicit you only need the middle two of the four lines to be in the inner for 'j' loop.
The bug/issue/problem isn't in the code but in phone numbers. I'm looking at my phone now and the '7' and '9' have four letters tied to them. Your for 'j' loop is hardcoded for only '3' letters. Not a big deal. Just some extra code for the special cases I guess. The important part is your code is recursive.
Second point is in testing the code. Two special numbers I'd be keen on testing are '0' and '1' since they don't have three or four letters associated with them. In fact, that's a good question to ask on how to handle them before you even coded the algorithm. Understandable how you'd miss that since you deferred coding getNextLetter(). Beware of abstracting code thought to be no-brainer busywork.
My final point is also in verifying the code. You can run this code on a 7-digit number and come up with a list of 7-letter strings. I'd take some assurance in knowing the number of unique strings produced agreed with, and here's where I admit I'm weak on counting theory, the combinations or permutations or whatever of 7-digits crossed with three or four letters per digit. I guess order matters so it'd be permutations? Anyway, I'd first inspect that the algorithm produced a few correct answers, then I'd look that the number of answers agrees with the predicted counting amount.
For my background... I'm a six year veteran of hardware design verification for a major networking company, and I'm in the interview process with Google. That's what's brought me to this site; research for my onsite interviews. I've also had interviews with major Wall Street banks so I've seen the whole brainteaser side of the equation, too.
In my first Google phone interview I was asked how I'd verify that a random number generator was truly random and to compare and contrast C++ vs. Java. I hope that helps some SDE/SDET candidates out there.
3 years ago
Shouldn't your for 'i' loop go from level up to in.length() instead of starting at 0? Every new call of myCutiePie() will be starting over at the beginning, only the new beginning on in[] will be a letter instead of a number. That'll give getNextLetter() some trouble.
And when you recursively call myCutiePie() I think you need the 2nd param to be (level + 1) instead of level++, for a couple of reasons. You shouldn't be able to or allowed to modify level since it's a pass-by-value param (although I'm a C++ coder and maybe it's a Java reference var and is ok?). Regardless of it being legal, it's still not giving the incremented version of level to the next call of myCutiePie(). Either do ++level or (level + 1).
3 years ago
3 years ago
3 years ago
# of permutation of 7 is 7!..
but the program generates 7*3 calls first, then each call generates 7*3, then ... which and goes 7 rounds( if u start level at 0) ...
the result is way more than expected and loaded with repeats.
rite code would be something like:
for each digit behind and includes currentDigit
swap with currentDigit
recursive call (move the currentDigit to the next)
end
* currentDigit start from 0, end at length-1.
the point is, 1 loop, not 2.
3 years ago
6072290623
and make
m paaw mad
m pabw mbd
m pacw mcd
So, there's no need to do any swapping in the main loop. This is not a permutations problem.
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
As Bob pointed out, 'i' should start from level, not 0. In fact, 'i' should only be equal to level - it should not increment until length. Consequently, Rakesh is also correct: the first 'for' loop is in fact, redundant. The code may be corrected completely by eliminating the 'i' for loop, and subsequently replacing 'i' by 'level' in the following 4 lines of code inside the 'j' for loop.