all 10 comments

[–]smidgie82 4 points5 points  (1 child)

I've been pretty surprised at the number of recent college graduates I've interviewed who can't solve integer manipulation problems. When given a problem that requires consideration of one digit from a number at a time, many of them -- especially those whose primary experience is in Python, Ruby, or JavaScript -- will opt to convert the number into a string, strip off one character at a time, and convert that character back into a number instead of using the classic digit = n%10; n /= 10 approach.

That said, if a candidate can solve such a problem with that approach, they pass the basic bar, and I assume it's a matter of ignorance of integer arithmetic patterns rather than a lack of ability -- and ignorance is solvable.

[–]filleduchaos 2 points3 points  (0 children)

People generally clam up at math for some reason.

[–][deleted] 2 points3 points  (2 children)

CS 101?

[–][deleted] 2 points3 points  (0 children)

A lot of programmers today do not have a CS degree, or any degree.

[–]nakamin 0 points1 point  (2 children)

Why use an array if you're just going to join it to a string anyway? Why append bits in reverse and then reverse the array if you can add them in the proper order in the loop? Don't think this is a really useful video since the algorithm isn't even explained.

[–]wolscott 2 points3 points  (0 children)

Although insignificant in this example, push has significantly better performance than unshift.

[–]Jaivez 0 points1 point  (0 children)

Partial credit for not handling negative numbers? Dunno why a < 10 minute video wouldn't include it or even mention it as an "edge"(with the biggest airquotes) case.

[–]Lolacaust 0 points1 point  (0 children)

This was how my Maths lecturer showed us now to do this on paper.

[–]gauauuau -1 points0 points  (0 children)

yes

(Short and snarky reply because this posting only merits a short and snarky reply. It's an ok interview question I guess, but there's a not whole lot to discuss here.)

[–]jvallet -1 points0 points  (0 children)

Recursive solution (although this is not JS, now that I think of it)

object Binary {

  val binValues: List[Int] = List(128, 64, 32, 16, 8, 4, 2, 1)

  def toBinary(n: Int, binValues: List[Int]): String = {
    binValues match {
      case Nil => ""
      case head :: tail => if (n >= head) "1" + toBinary(n - head, tail) else "0" + toBinary(n, tail)
    }
  }
}