Technical interviews - prep

Caporegime
Joined
18 Oct 2002
Posts
32,623
Of course, you have nothing to loose and everything to gain. I think I said this earlier but we ask lots of very challenging. Questions that most people don't get right. The people that call or email us afterwards with a solution we will be much more likely to hire than those that just gave up completely.

Tell them that your mind blanked and you knew of better solution once you jumped in the car. It is normal, especially under stress and pressure of an interview to seize up.

These technical tests are not a flawless indicator of programming ability and a good interviewer should make adjustments. Working under stress of an interview is different to everyday coding and is different to tight deadlines in the job. Last night we had a massive system failure right before a major pot ethical investor was scheduled to make tests and potentially invest millions- we hacked away for into the small hours on the back of a string of 12 hour days and no weekend. I had even stopped for the night and had a few beers! That was coding under pressure, and it was still way different to an interview. Sadly the failure was out if our control.

The thing is there aren't any good alternatives. You can get people submitting code samples but you have no way of knowing how many people contributed, how long they took, what code review process was in place, what help was found from stack overflow etc. And that is if the person has code that they can share, you certainly can't share code form previous employers.
 
Last edited:
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
Didn't get that one :(

I do however have a couple of second interviews in the new year :)

Also I submitted my CV to IMDB and I was sent a link to a codility test which I have to complete by tomorrow. So I've spent the past couple of days preparing for it. Click on the link for the test tonight and......

500: system error

The team has been notified about the issue and will act on it shortly.

Argh!!!

Edit ok sorted and submitted. Codility is an interesting way of testing, thankfully the questions I was given weren't as tricky as some of the questions they ask
 
Last edited:
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
And I passed that test! Cool! :D

Telephone interview with some peeps in Seattle in the new year!

Looks like another technical interview, using some collaborative edit tool. Sounds scary!
 
Last edited:
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
So on Friday I have another interview, the technical side of things there is a test. Direct quote from recruitment agent

There will be a refactoring test involved in the interview process. Be prepared for this, it will involve IDEs & Eclipse. The format will be talking through what you’d change in the code and why, so quite a practical exercise. You may also be tested on some basic Java questions, perhaps in areas you haven’t put any thought to for some time, so I suggest you read up on some basics of ‘textbook’ Java.

Doesn't sound too hard :confused:

I'll just assume that means making code more modular and perhaps separating some stuff out in to different classes etc.
 
Associate
Joined
29 Apr 2004
Posts
696
Get some unit tests in place before you do the refactoring. Then you could just go through each of the SOLID principles and explain why you're refactoring the bits of code.
 
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
Just going through some of the questions from "Cracking the coding interview". One of them says

Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structures?

Not entirely sure what she means by additional data structures? If I could use additional data structure I'd use a set, but since I can't I did it this way

Within the requirements? She uses some sort of bit vector in her solution

Code:
  public boolean hasAllUniqueCharacters(String s) {
    char[] chars = s.toCharArray();
    Arrays.sort(chars);
    char current = '\u0000';
    for(int i=0; i < chars.length; i++) {
      if(current != chars[i]) {
        current = chars[i];
      } else {
        return false;
      }
    }
    return true;
  }
 
Associate
Joined
29 Apr 2004
Posts
696
Just going through some of the questions from "Cracking the coding interview". One of them says



Not entirely sure what she means by additional data structures? If I could use additional data structure I'd use a set, but since I can't I did it this way

Within the requirements? She uses some sort of bit vector in her solution

Code:
  public boolean hasAllUniqueCharacters(String s) {
    char[] chars = s.toCharArray();
    Arrays.sort(chars);
    char current = '\u0000';
    for(int i=0; i < chars.length; i++) {
      if(current != chars[i]) {
        current = chars[i];
      } else {
        return false;
      }
    }
    return true;
  }

Could rewrite that as the following as the setting current seems redundant to me:
Code:
    public boolean hasAllUniqueCharacters(String s) {
        char[] chars = s.toCharArray();
        Arrays.sort(chars);
        for(int i=0; i < chars.length - 1; i++) {
            if (chars[i] == chars[i + 1]) {
                return false;
            }
        }
        return true;
    }
 
Caporegime
Joined
18 Oct 2002
Posts
32,623
The Char Array is a new data structure.

The bit check is the most logical and by far the fastest solution IMO. All it is doing it converting the characters to by 0 aligned integer and setting bits in in an int32 variable. If a bit has already been set then the character has been seen before.

E.g. given the bits (reduced to 8bit for simplicity)
Code:
0 1 0 1 1 0 1 1
The Following are true if you were to check the bit is set:
Code:
0 1 0 0 0 0 0 0

0 0 0 0 0 0 0 1

0 0 0 0 0 0 1 0

0 0 0 0 1 0 0 0

0 0 0 1 0 0 0 0


As mentioned on the stackoverflow link though, this requires some constraints on the string, e.g. being the lower case 26 letters.


This is the typical kind of question we ask candidates, of the string is long or you do this frequently enough then a bit mask approach will be insanely faster.

This kind if technique is quite common in programming, it is extremely fast and efficient. With strings a lot of care is needed but it can be useful for formatted text, e.g. names in a database. An example core to ur bussiness is we have to do machine learning on a system that is represented by around 50 different states. We could have a load of bools, e.g.
Code:
// Person attributes:
bool male;
bool tall;
bool rich;
bool fat;
bool ugly;
bool employed;
bool goodCreditHistory;
bool hasLoan;
...
But that takes a lot of space and is slow to parse. Instead if each bool was simply 1 bit in a 32/64bit integer then you can quickly test many things with bit masks.
Code:
int person = initPerson(...);

bool isDatableChick() {
  return RICH_ATTACTIVE_THIN_FEMALE  & person; 
}

bool giveLoan() {
  return GOOD_CREDIT_NO_LOAN & person; 
}


Bitmasks are in general very useful to know.
 
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
Sorry humour me a minute whilst I try to understand

get bit

Code:
boolean getBit(int num, int bit) {
  return ((num & ( 1 << bit)) !=0);
}

Is this for checking if a bit is set? So for example

Code:
num = 4
bit = 2
            0100&
0001 << 2 = 0100
            ----
            0100

num = 8
bit = 2
            1000&
0001 << 2 = 0100
            ----
            0000

Seems to work for those, but 8?

Code:
num = 8
bit = 4
             1000&
0001 << 4 = 10000
            -----
            00000

Shouldn't bit 4 be set?
 
Soldato
Joined
18 Oct 2002
Posts
3,926
Location
SW London
I think it fails that scope as you are converting the string to a char array. There are a few answers on stack overflow discussing this: http://stackoverflow.com/questions/...-characters-comparing-my-solution-to-cracking

God, that bit mask solution in the OP of the link is horrible.
It's working on the assumption that there will only ever be 26 distinct values in the input (lowercase a-z) even though a char itself is a 16-bit data type and could be any one of 65,536 possible values.
It doesn't validate the inputs to check that it is in the correct form for the check, so it would either silently fail, or throw some sort of exception depending on the input used.
 
Caporegime
Joined
18 Oct 2002
Posts
32,623
Sorry humour me a minute whilst I try to understand

get bit

Code:
boolean getBit(int num, int bit) {
  return ((num & ( 1 << bit)) !=0);
}

Is this for checking if a bit is set? So for example

Code:
num = 4
bit = 2
            0100&
0001 << 2 = 0100
            ----
            0100

num = 8
bit = 2
            1000&
0001 << 2 = 0100
            ----
            0000

Seems to work for those, but 8?

Code:
num = 8
bit = 4
             1000&
0001 << 4 = 10000
            -----
            00000

Shouldn't bit 4 be set?


You have an off by 1 error, 0010 has the second bit set. 0100 has the 3rd but set == 4. The decimal 4 does not have the 2nd bit set.
 
Associate
Joined
29 Apr 2004
Posts
696
Sorry humour me a minute whilst I try to understand

get bit

Code:
boolean getBit(int num, int bit) {
  return ((num & ( 1 << bit)) !=0);
}

Is this for checking if a bit is set? So for example

Code:
num = 4
bit = 2
            0100&
0001 << 2 = 0100
            ----
            0100

num = 8
bit = 2
            1000&
0001 << 2 = 0100
            ----
            0000

Seems to work for those, but 8?

Code:
num = 8
bit = 4
             1000&
0001 << 4 = 10000
            -----
            00000

Shouldn't bit 4 be set?

It's doing a bitwise AND operation. In the last case the number is 8, so the forth bit is set but your second variable has the first bit shifted right 4 places into the fifth bit. This leads to the bits being "on" in different places and so none are set when you do the bitwise AND.
 
Caporegime
Joined
18 Oct 2002
Posts
32,623
God, that bit mask solution in the OP of the link is horrible.
It's working on the assumption that there will only ever be 26 distinct values in the input (lowercase a-z) even though a char itself is a 16-bit data type and could be any one of 65,536 possible values.
It doesn't validate the inputs to check that it is in the correct form for the check, so it would either silently fail, or throw some sort of exception depending on the input used.

I assume the question asks or monies that the string constrains only the 26 lower case letters, event then there is some oddities such as checking if the string is over 256 in size instead of 26. Otherwise the code is broken.

In typically interview questions you simplify the problem, e.g. assuming inputs are normalized.
 
Soldato
OP
Joined
1 Mar 2003
Posts
5,508
Location
Cotham, Bristol
You have an off by 1 error, 0010 has the second bit set. 0100 has the 3rd but set == 4. The decimal 4 does not have the 2nd bit set.

Yes but the result of 1<<4=16 doesn't it? So 8 & 16 = 01000 & 10000 = 00000

The question itself doesn't mention any assumptions, the answer does however
 
Last edited:
Back
Top Bottom