Open Side Menu Go to the Top

03-28-2016 , 10:45 AM
Quote:
Originally Posted by RustyBrooks
Ah, so the stipulation on the maximum size of the integers matters after all. I should have seen that probably. If someone insisted it could be done in nlogn I think I might have eventually come across it.
this. it is immensely harder to be given the problem and just asked, "what is the best running time that's constant memory, and give me the algorithm for it?" vs being asked, "find an nlogn algorithm that's constant memory"
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
03-28-2016 , 10:47 AM
Quote:
Originally Posted by Bantam222
Personally I feel this question is very hard and it's not fair to 'no hire' a candidate because they cannot answer this question in O(n log(n)) runtime.
Quote:
Originally Posted by RustyBrooks
But I think it's a terrible interview question. It's the equivalent of something like crossword solving or something.
Agree with both takes here but I think even problems like this can be properly used by a good interviewer - the interviewer should progressively give enough hints to allow any reasonably smart person who understands divide & conquer to get it and you're judging based on the interaction you had with the candidate up to that point. Yeah it's really bad if you just throw this out, sit there, and watch the candidate squirm and judge based on what's been produced after some amount of time. But some people react quite poorly to being stuck on an interview problem, throw tantrums or make declarations about how the problem is wrong and they are right and also can't pay attention to hints or anything the interviewer is saying when they are in the middle of solving a problem. These are all red flags and rightfully so. But I guess there are better problems for that too.

Quote:
Once you see the solution, programming it is really trivial.
I don't know about this - lots of off-by-one error possibilities here - you have to keep track of a bunch of stuff (min, max, middle, count) and I think correctly updating all of those is not trivial for a whiteboard type of exercise.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 10:51 AM
FizzBuzz in Scala... I'm sure it's less than amazing:

Code:
object FizzBuzz {
  def fizzy(i: Int, d: Int, s: String): String = {
    if (i % d == 0) s else ""
  }

  def fizz_buzz () = {
    for (i <- 1 to 100) {
      var s = ""
      s += fizzy(i, 3, "fizz")
      s += fizzy(i, 5, "buzz")
      if (s == "") {
        s += i
      }
      println(s)
    }
  }
}

object HelloWorld {
  def main(args: Array[String]): Unit = {
    FizzBuzz.fizz_buzz()
  }
}
Notes:

The String return type on fizzy() isn't needed, but I put it there because, why not? Seems to run a lot faster with it.

Obviously, it is a bit overdone, but just wanted to experiment with stuff.

The args: in main() are stndin, but optional. Don't know why that is, but I'm guessing it is due to allowing zero-length arrays?

I have no clue what Unit means.

Last edited by daveT; 03-28-2016 at 10:57 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 10:54 AM
Quote:
Originally Posted by RustyBrooks
My first semester of programming was about 20 years ago. Guess how many times I have needed to turn an n^2 algorithm into a clever nlogn algorithm since then.
About 350?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 10:58 AM
Quote:
Originally Posted by RustyBrooks
My first semester of programming was about 20 years ago. Guess how many times I have needed to turn an n^2 algorithm into a clever nlogn algorithm since then.
42?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 10:58 AM
Quote:
Originally Posted by daveT
About 350?
Probably more like 3.50
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 11:01 AM
candybar people at my work are starting to ask about the benefit of angular 2 over angular 1. I know the basics - no more scope or controllers, instead it's all contained within components. Which is moving more towards the web components standard (right?). And no more 2-way data binding out of the box.

What are some other blurbs I can say to sound smart?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 11:04 AM
Quote:
Originally Posted by daveT
I have no clue what Unit means.
It's like void in Java, except it's an actual type with one possible value which allows the type system to deal with functions that return nothing generically along with functions that return something. For example:

http://www.scala-lang.org/api/curren...cala.Function1

If this was handled like C/C++/Java/C#, they'd need a separate type Procedure[-T] to handle a unary function that doesn't return a value and you'd have to handle them separately. This is a major pain for type inference in C# for example because this propagates to things like futures/promises.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 11:13 AM
Quote:
Originally Posted by daveT
FizzBuzz in Scala... I'm sure it's less than amazing:

Code:
object FizzBuzz {
  def fizzy(i: Int, d: Int, s: String): String = {
    if (i % d == 0) s else ""
  }

  def fizz_buzz () = {
    for (i <- 1 to 100) {
      var s = ""
      s += fizzy(i, 3, "fizz")
      s += fizzy(i, 5, "buzz")
      if (s == "") {
        s += i
      }
      println(s)
    }
  }
}

object HelloWorld {
  def main(args: Array[String]): Unit = {
    FizzBuzz.fizz_buzz()
  }
}
Notes:

The String return type on fizzy() isn't needed, but I put it there because, why not? Seems to run a lot faster with it.

Obviously, it is a bit overdone, but just wanted to experiment with stuff.

The args: in main() are stndin, but optional. Don't know why that is, but I'm guessing it is due to allowing zero-length arrays?

I have no clue what Unit means.
Unit essentially means void


Not tested:

Code:
object HelloWorld {
  def main(args: Array[String]): Unit = {
    fizzbuzz(100)
  }

  def fizzbuzz(range: Int) = {
    (1 to range).foreach(num =>
      (num % 3, num % 5, num) match {
        case (0, 0, _ ) => println("fizzbuzz")
        case (0, _, _) => println("fizz")
        case (_, 0, _) => println("buzz")
        case _ => println(num)
      }
    )
  }
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 11:16 AM
Quote:
Originally Posted by suzzer99
candybar people at my work are starting to ask about the benefit of angular 2 over angular 1. I know the basics - no more scope or controllers, instead it's all contained within components. Which is moving more towards the web components standard (right?). And no more 2-way data binding out of the box.

What are some other blurbs I can say to sound smart?
Zones!

http://blog.thoughtram.io/angular/20...angular-2.html

Also standardizing on TypeScript I think just makes things a little cleaner for those of us who have to deal with class-based OO the other half the time but that may or may not be everyone's cup of tea.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 12:12 PM
Quote:
Originally Posted by RustyBrooks
My first semester of programming was about 20 years ago. Guess how many times I have needed to turn an n^2 algorithm into a clever nlogn algorithm since then.
Seriously. This sort of thing is so hot in interviews, who can come up with the best brain teasers to really make interviewees have to "show off their skills" and it doesn't matter for anything 99% of the time you're doing the job they're actually hiring you for, with very limited exceptions.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 12:18 PM
Quote:
Originally Posted by RustyBrooks
Probably more like 3.50
I assumed zero or maybe once.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 12:23 PM
Quote:
Originally Posted by goofyballer
Seriously. This sort of thing is so hot in interviews, who can come up with the best brain teasers to really make interviewees have to "show off their skills" and it doesn't matter for anything 99% of the time you're doing the job they're actually hiring you for, with very limited exceptions.
Maybe we wouldn't have such a shortage of hireable people if they could solve these useless brain teasers that never matter in the actual job they do!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 01:14 PM
I can't tell if it's a fad or not. I can tell you that the very first time I had to do one of these "aha" problems was around 2009 or 2010, never before that. Whiteboarding was common, "tricky" questions regarding your programming language were common. So the first time I ran into one of these puzzle ones I just gave the first off the cuff method that came to me, which was of course atrocious because like here it was probably n^2 when it should have been way faster.

I got a real blank look from the interviewer, and he was like "uh, I think you can do much better" and then I realized what he really wanted. I stumbled a little from there - I was actually completely unfamiliar with the class of the puzzle, wheras he was a former national champion from one of those programming contest leagues.

Since then, probably 80% of interviews have had these gotcha things. Sometimes I already know the answer, sometimes I get there in time, sometimes I don't. It's not great. There is nothing like being a talented veteran and being told you're not good enough to do your job because you can't do one of these puzzles.

It's only one step up, imo, from google techniques (since abandonded, because duh, they don't work) of asking about how many violins there are in toronto or how many ping pong balls you can fit in a 747, or the old MS questions like "why are manhole covers round" and similar riddles.

Guess what: no one has any idea how to tell if someone will be a good fit. It's pretty easy, imo, to weed out the completely unfit people but you're left with people that might be only 70:30 in favor of being an actual good employee.

No one ever likes to fire people, so they try to limit hiring up front. They probably leave some good potential employees behind.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:00 PM
Quote:
Originally Posted by RustyBrooks
No one ever likes to fire people, so they try to limit hiring up front. They probably leave some good potential employees behind.
People should be able to change jobs more often.

If you busted your absolute ass on a project for 3 months, there is a very real possibility you have done more "work" than someone comfortably mid-tier at an Extermely Mega Corp for 12-18 months (and some not 0% probably even longer)

However, employers and employees see "work engagements" as needing to be 12-24 months. I think it is basically out of the ****ty industry of recruiting and such charging so much to hire people, that they basically expect everyone to last for 3-5 years.

I think transient jobs would be a huge benefit for more people and companies. If it was easier to find jobs, and contract gigs were easier, I imagine a whole lot of people would take up the opportunity to work for 3-5 months and then take time off and do something else.

Instead companies have to be very vigilant of using contractors instead of employees because of laws (except the unicorns who have to pay lawyers to break the rules and hopefully set precedent for all of us)

Overall hiring is so broken in so many ways it is sometimes insane to realize how many mangers spend >50% of their time just on hiring/firing/promoting/people stuff.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:02 PM
Am I missing something? Isn't the solution to just sort the array in n log n time? n log n + n = O(n log n).
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:12 PM
Quote:
Originally Posted by KatoKrazy
Am I missing something? Isn't the solution to just sort the array in n log n time? n log n + n = O(n log n).
You're not allowed to modify the array, and you have to use constant memory. Sorting the array out-of-place would require memory the same size of the list.

There is a solution posted above that does it in n log n without sorting though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:13 PM
Quote:
Originally Posted by RustyBrooks
You're not allowed to modify the array, and you have to use constant memory. Sorting the array out-of-place would require memory the same size of the list.

There is a solution posted above that does it in n log n without sorting though.
Oops, missed the part about not modifying the array.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:43 PM
Quote:
Originally Posted by KatoKrazy
Am I missing something? Isn't the solution to just sort the array in n log n time? n log n + n = O(n log n).
sorting forces either non constant memory or mutation, both of which are disallowed
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:50 PM
Quote:
Originally Posted by PJo336
Unit essentially means void


Not tested:

Code:
object HelloWorld {
  def main(args: Array[String]): Unit = {
    fizzbuzz(100)
  }

  def fizzbuzz(range: Int) = {
    (1 to range).foreach(num =>
      (num % 3, num % 5, num) match {
        case (0, 0, _ ) => println("fizzbuzz")
        case (0, _, _) => println("fizz")
        case (_, 0, _) => println("buzz")
        case _ => println(num)
      }
    )
  }
}
it passed as written!
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:53 PM
Quote:
Originally Posted by suzzer99
candybar people at my work are starting to ask about the benefit of angular 2 over angular 1. I know the basics - no more scope or controllers, instead it's all contained within components. Which is moving more towards the web components standard (right?). And no more 2-way data binding out of the box.

What are some other blurbs I can say to sound smart?
When is support for 1 ending?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:55 PM
Quote:
Originally Posted by daveT
When is support for 1 ending?
1 is still in active development - there's no such timeline AFAIK.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 02:57 PM
Quote:
Originally Posted by candybar
1 is still in active development - there's no such timeline AFAIK.
do you do scala professionally?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 03:03 PM
Quote:
Originally Posted by gaming_mouse
do you do scala professionally?
Not really - I've been messing around with it since like 2008 or so but haven't actually used it professionally. The closest I came was when I wrote a prototype for an internal demo where I used Scala and Play but even that started more as a hobby project. I've done quite a bit of both C#/Java-style OO and ML-style FP (my favorite pl in college was OCaml) so Scala has always felt very natural.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
03-28-2016 , 03:31 PM
I was asking about Angular 1...
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m