Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

07-19-2018 , 02:12 AM
I should be sleeping but since I'm not tired, here's maybe a cuter JS solution, along the same lines, but it returns immediately if it finds the first character has a repeat :P

I'm a little embarrassed at this point how much time I've spent fiddling with this toy problem today. It's kind of relaxing though.

Code:
function findFirstRepeat(test) {
  const seen = {};
  let solution = -1;

  test.split('').some((c, i) => {
    if (!seen.hasOwnProperty(c)) {
      seen[c] = i;
    } else if (solution < 0 || seen[c] < solution) {
      solution = seen[c];
    }
    
    return solution === 0;
  });
  
  return solution >= 0 ? test[solution] : false;
}

console.log(`earliest repeat: ${findFirstRepeat('abadfdasdfasdfasfasf')}`);
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:14 AM
Quote:
Originally Posted by well named
This was wrong actually, the order doesn't matter. I must have had some other problem.

Incidentally, this is why I don't like whiteboard problems. I tend to think of some general approach (use a hash to store the first position each character was seen in, keep track of the earliest duplicate...) and then I start writing some code and it doesn't work and I don't quite understand why and then I play with it -- running it a bunch of times -- and then it works. That iterative process works well for me IRL but isn't easy to do at a whiteboard.

Basically I think I have trouble keeping an entire problem in my head, I need the scratch space.
This is exactly what I did. But he ushered me off the stage before I could even finish. It was humiliating. I did email my answer to the original person I talked to later.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:18 AM
Quote:
Originally Posted by OmgGlutten!
suzzer, i would google cracking the coding interview questions solved with javascript and look that over before your next white board.
I have version 1, and now version 6. Read version 1 a long time ago one and was annoyed. Haven’t cracked version 6 yet.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:55 AM
On a side note - why does jsfiddle not have a panel for the console.log? It's a big PITA for me on a short-screen Mac to see the code and launch inspector and see the console.log output at the same time. Or am I missing something?

Edit: Well problem solved - I switched to document.write instead.

Last edited by suzzer99; 07-19-2018 at 02:57 AM. Reason: x
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 03:06 AM
i wouldn't read the book. i would find some github reps from people who have worked through them already. then try to glance/read them over.

like this

https://github.com/careercup/CtCI-6t...ion-JavaScript
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 03:07 AM
The single best book I’ve read lately has been “The Pragmatic Programmer.”

It’s basic concepts we all know, and I did too, but it’s written in a very simple and clear way that reinforces things well.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 04:35 AM
Ok I think this is about as low as you can get from a big O POV. But code clarity sucks, and who knows how much processing power stuff like split() is taking up.

Code:
function findFirstRepeat(input) {
  const charHash = {};
  const charArray = input.split('');
  const matchArray = new Array(charArray.length);
  
  charArray.forEach((char, index) => {
    if (charHash[char] !== undefined) matchArray[charHash[char]] = 'MATCH';
    else charHash[char] = index;
  });
  
  return charArray[matchArray.indexOf('MATCH')] || 'none found';
}

document.write(findFirstRepeat("abcdebcd") + "<br/>") // should return "b"
document.write(findFirstRepeat("abba")) // should return "a"
I thought about just using the original string instead of splitting it into charArray - and replacing the matched character with * or something. But then if * is in your string you're screwed. So you have to use an array unless you know for sure some characters won't appear in your string.

Last edited by suzzer99; 07-19-2018 at 04:43 AM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 06:43 AM
Quote:
Originally Posted by Grue
Anyone a principal/staff/architect SE (next step above lead)? What'd you do to get there? Its my medium term goal (~2 years) at my current place.
Easiest path is to work at a rapidly growing company. Likewise advancement in roles is very difficult in a flat or shrinking company. They already have those roles filled and those guys aren't leaving until they retire.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 08:01 AM
Quote:
Originally Posted by suzzer99
Ok I think this is about as low as you can get from a big O POV. But code clarity sucks, and who knows how much processing power stuff like split() is taking up.
Something I think you really need to tighten up is your understanding (or your expression of) big O notation. All the algorithms posted are the same in big O, O(n). From a computer science point of view they're all equivalent, pick the one that you can write correctly on the whiteboard.

Technically an O(n) solution takes
cn + k
where c and k are constants and different solutions will have different values of these. Some might work better for small n or for large n depending on the values of c and k, but all will outperform an O(n^2) or even O(nlogn) once n gets large enough, which is the point of big O.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:38 PM
Quote:
Must know the following very well:
- Node
- React
- SQL Databases
- AWS Server Management

You must work very quickly, write clean and organized code and work well with others. We have a fun team and our office is a very cool place to work from.

Very competitive packages, tokens from our ICO & equity offered. 72k salary.
From a craigslist job posting.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:39 PM
Quote:
Originally Posted by RustyBrooks
Something I think you really need to tighten up is your understanding (or your expression of) big O notation. All the algorithms posted are the same in big O, O(n). From a computer science point of view they're all equivalent, pick the one that you can write correctly on the whiteboard.

Technically an O(n) solution takes
cn + k
where c and k are constants and different solutions will have different values of these. Some might work better for small n or for large n depending on the values of c and k, but all will outperform an O(n^2) or even O(nlogn) once n gets large enough, which is the point of big O.
Right. Makes sense.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:43 PM
Quote:
Originally Posted by suzzer99
From a craigslist job posting.
The part you bolded isn't the most LOL part of that posting
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 02:46 PM
In my projects in algorithms course we had a very interesting project where there was a very easy to implement O(n) solution to a problem that could naïvely be solved O(n^2) - so naturally your instinct as a student is to go oh, this is it then. However the nature of the problem was such that the constant factors were way too high if you’re not careful and you could get really horrible outcomes if you didn’t take steps to alleviate that. Constant factors matter a lot more than people realize I think.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 03:25 PM
Quote:
Originally Posted by RustyBrooks
The part you bolded isn't the most LOL part of that posting
yeah those 4 things couldn't be farther from each other good luck with that. Might as well have put "also you must speak fluent Dutch" on it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 03:41 PM
I've worked reasonably extensively with all 4 of those things professionally, amusingly enough. I'm not exactly sure if I qualify as knowing react very well at this point, though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 03:54 PM
Quote:
Originally Posted by well named
This was wrong actually, the order doesn't matter. I must have had some other problem.

Incidentally, this is why I don't like whiteboard problems. I tend to think of some general approach (use a hash to store the first position each character was seen in, keep track of the earliest duplicate...) and then I start writing some code and it doesn't work and I don't quite understand why and then I play with it -- running it a bunch of times -- and then it works. That iterative process works well for me IRL but isn't easy to do at a whiteboard.

Basically I think I have trouble keeping an entire problem in my head, I need the scratch space.
ya I write code and output stuff as I go along. its always wrong and then I fix it as I go further. my friend calls it error driven development.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 03:59 PM
Quote:
Originally Posted by Victor
error driven development.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 05:56 PM
Quote:
Originally Posted by RustyBrooks
The part you bolded isn't the most LOL part of that posting
Quote:
Originally Posted by Grue
yeah those 4 things couldn't be farther from each other good luck with that. Might as well have put "also you must speak fluent Dutch" on it.
I was thinking "tokens from our ICO" but there's a lot to love about that posting for sure
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 06:08 PM
This morning, I had training which included the importance of avoiding gender discrimination. This afternoon, I programmed an actuarial widget. It gets the right answer for males but wrong for females.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 06:29 PM
Quote:
Originally Posted by Grue
yeah those 4 things couldn't be farther from each other good luck with that. Might as well have put "also you must speak fluent Dutch" on it.
I was referring to the ICO part.

The requirements don't seem that weird to me, I know plenty of guys that could fill it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 06:42 PM
You know expert full stack javascript developers who know/work with SQL instead of NoSQL and also know devops/sysadmin stuff? I don't.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 06:44 PM
I have plenty of SQL and noSQL. I was full stack before noSQL existed b*tch.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 06:46 PM
Just had an in person interview that went approximately infinity times better than my two interviews yesterday. I was much more on my game.

In retrospect maybe trying to cram two hour long tech grillings into 3 hours - the day after ending a 7 month road trip - might not have been the best idea.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 07:03 PM
Quote:
Originally Posted by Grue
You know expert full stack javascript developers who know/work with SQL instead of NoSQL and also know devops/sysadmin stuff? I don't.
Sure. There's a guy I work with who's main job is the UI for our product (which is angular rather than react, but I figure roughly equivalent). He's also deeply responsible for our deployment process, which is all to AWS. He knows SQL as well as anyone else I know.

I don't know JS but 10 years ago most people would have called me a "front end" developer (or full stack) since I wrote desktop applications. Hell, give me a year and maybe I'll be an expert at some kind of JS framework which is already tottering off to old age. Actually back in the mists of time before there really were "frontend developers" I wrote all the HTML/CSS/JS on the websites I worked on - there was just a lot less JS in those days.

Nosql is a fairly recent thing, but there are probably lots of older FE engineers who are familiar with SQL
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
07-19-2018 , 07:10 PM
In 2006-2007 I worked at a small consultancy where they described themselves as "generalists" which isn't nearly as sexy as "full stack". On some projects one dev did everything from the database schema up to the CSS.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m