Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Unspun posted:

Use a pointer at each end of the string and move them towards each other. Stacks? Arrays?! Christ! gently caress!!

if this is your reaction in an interview then the interview has served its purpose

Adbot
ADBOT LOVES YOU

Jeb Bush 2012
Apr 4, 2007

A mathematician, like a painter or poet, is a maker of patterns. If his patterns are more permanent than theirs, it is because they are made with ideas.
that's gonna give you the wrong answer because you'll see "()()", match the leftmost and rightmost character, and then conclude that the parentheses don't match because ")(" doesn't match

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Also, again, that is probably an incorrect solution (but it depends on what the precise question is).

EDIT: right, what JEB! said ^^^^

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


It's a context free language. Emulate a pushdown automaton and move on with your life.

Unspun
Apr 6, 2007

You might feel your bones loose or discomforting.
It's normal!
Your legs are just developing and changing into being a Milky Point Millionaire.

Jabor posted:

if this is your reaction in an interview

This is the Coding Horrors thread of something awful dot com, apologies for any confusion

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Unspun posted:

This is the Coding Horrors thread of something awful dot com, apologies for any confusion

fair enough, I guess it is the appropriate place to be absolutely certain of yourself while also being totally wrong

Volguus
Mar 3, 2009

Jabor posted:

fair enough, I guess it is the appropriate place to be absolutely certain of yourself while also being totally wrong

No, that place is called "production".

Happy Thread
Jul 10, 2005

by Fluffdaddy
Plaster Town Cop

My wife pointed this out too when I tried the problem with her. Came here to relay the message but someone's beaten me to it. Spoke too soon earlier when I was so impressed by it. Oops.

Not looking forward to myself getting tripped up on special cases like that soon in interview problems.

One thing I hate is how many of them are expressed purely as puzzles. Here's a problem of searching through m bags of n permutations of o strings of...... who cares. It reminds me of none of the situations I normally face as a programmer and does not put me in my best thinking mood*. I don't solve puzzles, I solve problems. Put one of those in front of me and phrase it as an engineering need and I'll get it.

*Another thing that does not put me in my best thinking mood: Having someone look over my shoulder or expecting a conversation while I'm trying to think through a problem. I don't want to just draw a blank because I'm picturing what the interviewer's expectant face looks like right that moment, or worse, looking at it in person. They wouldn't force me to do that on the job, so I don't see why it's a good test to try it during an interview. Different kinds of pressure that people work well under, etc.

Can I hang up the phone with them while I'm thinking it over? Because that is obviously what I would do in real life, on the job. I'd never just trust my solution that I found to something in real time mid-conversation.

Happy Thread fucked around with this message at 08:44 on Jun 18, 2019

Ola
Jul 19, 2004

"...well, I would simply google "FizzBuzz optimal solution" and copy/paste whatever has the most upvotes".

"You're hired".

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If all the problems you needed to solve on the job were small enough to work out in a 1-hour interview, you wouldn't get paid very much. Everyone is aware that the toy problems used for interviews aren't completely representative of what the job actually involves - the point is more about your general ability to solve problems with code than it is about your ability to identify the solution to this particular artificial problem.

So no, just not saying anything to the interviewer and then coming back twenty minutes later with a canned solution is not a good way of showing off your problem solving skills, let alone the communication skills you'll also need to be successful in a programming job.

Ola
Jul 19, 2004

I have such an interview tomorrow, so I had a go in JS. Shred me.

code:
function balanceBrackets(string){
  var brackets = {'}':'{',']':'[',')':'(','>':'<'};
  var stack = [];
  for (var c in string){
    if ('{[(<'.includes(string[c])){
      stack.push(string[c]);
    }
    if (')]}>'.includes(string[c])){
      var t = stack.pop();
      if (typeof t == undefined || t != brackets[string[c]]){
        return false;
      }
    }
  }
  return stack.length==0;
}
code:
balanceBrackets("{$$[fdasfsa<fdaf>####]%@#}")
true
balanceBrackets("{$$[fdasfsa<fdaf>####]%@#}(")
false
balanceBrackets("{$$[ff}fff]")
false

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
The first question I would have when presented with the problem is, what's a "bracket" here? because I'm sure Unicode has lots of funny characters that are brackets. and the original statement just says it's "a string", it doesn't say "an ascii string" or w/e.

Soricidus
Oct 21, 2010
freedom-hating statist shill

Hammerite posted:

The first question I would have when presented with the problem is, what's a "bracket" here? because I'm sure Unicode has lots of funny characters that are brackets. and the original statement just says it's "a string", it doesn't say "an ascii string" or w/e.

Hmm. Good point. So first up we’re going to need a BracketProviderFactory interface,

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Soricidus posted:

Hmm. Good point. So first up we’re going to need a BracketProviderFactory interface,

Don’t forget the CorrespondingBracketComparerFactoryService.

NtotheTC
Dec 31, 2007


Guys, guys this can all be achieved with regex if you use lookaheads. It's a regular language unlike html!

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Not in test cases, therefore not my problem.

In honesty 90% of a technical interview is seeing how you solve/iterate on problems. So add test case and fix.

Trammel
Dec 31, 2007
.

Nolgthorn posted:

Strip everything except brackets from the string, if it's an odd length fail, then match half the indexes against the opposite using a switch statement.

I like it.
code:
#!/usr/bin/env perl
$/=''; $i = <STDIN>;
$i =~ tr/{}[]()//cd;
$l = length($i);
exit 1 if $l & 1;
$r = "(.{1,@{[$l/2]}})";
($a, $b) = $i =~ /$r/g;
$b =~ tr/{}[]()/}{][)(/;
exit($a ne reverse($b))

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

Trammel posted:

I like it.
code:
#!/usr/bin/env perl
$/=''; $i = <STDIN>;
$i =~ tr/{}[]()//cd;
$l = length($i);
exit 1 if $l & 1;
$r = "(.{1,@{[$l/2]}})";
($a, $b) = $i =~ /$r/g;
$b =~ tr/{}[]()/}{][)(/;
exit($a ne reverse($b))

immediately marched out the door for asking me to read perl

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
I'm sorry I cannot read your code because I am not a terminator.

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

leper khan posted:

Don’t forget the CorrespondingBracketComparerFactoryService.

1. First, we need to create a settings registrar. The idea behind the settings registrar is that we want to conceive of the languages used to determine what the brackets are as a simple POCO so we can inject it into the service layer later, but we also want to solve configuration settings in general. It's really annoying just to be able to configure settings in a webconfig key, so the idea behind the settings registrar is from the developer's perspective, they just inject the poco, whereas we can use the magic of dependency injection to create a hierarchy of settings. The settings registrar will flatten the pocos into key value pairs (as all forms of data persistence, in essence, boil down to key value pairs) - this allows us to pull settings hierarchically from a web config / mongo / even an oracle database using a minimum of effort, and the developer need not know where the settings actually came from.

2. In order for the settings registrar to resolve this particular poco, we need to create a ILanguageReader - this will act as the class for reading brackets specified for a language.
We next need an ILanguageResolver - the resolver will use reflection to turn the key value pairs into the original poco specified.

3. Finally, we have a set of pocos indicating what brackets go with which language. What we can do is consider every language an IBracketPreprocessor - the base bracket preprocessor obviously should be EnglishBracketPreprocessor, but we can register the additional languages returned by the pocos as decorators for the original preprocessor. Using the magic of generics, we can declare a BracketPreprocessor<T> that can be instantiated from the injected settings pocos (we obviously need the base class to be a real preprocesor, but the additional preprocessors will take the previously applied preprocessed brackets as the argument in the constructor, following the decorator pattern.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Dumb Lowtax posted:


Can I hang up the phone with them while I'm thinking it over? Because that is obviously what I would do in real life, on the job. I'd never just trust my solution that I found to something in real time mid-conversation.

As an interviewer I generally care more about your thought process than the actual answer given, especially the first pass. Don't hang up, start naive and acknowledge that you may/will have a clean up pass. If you hang up and then come back with an answer you might just have come to this thread for help which isn't the point of the exercise.

canis minor
May 4, 2011

eh... https://stackoverflow.com/questions/52969755/how-to-check-the-sequence-of-opening-and-closing-brackets-in-string

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense
ma galaxybrain

JavaScript code:
const START = '{[(<';
const END = '}])>';

function check(str) {
    const buffer = [];
    for (const char of str) {
        if (START.includes(char)) {
            buffer.push(char);
            continue;
        }
        const index = END.indexOf(char);
        if (index > -1 && buffer.pop() !== START[index]) {
            return false;
        }
    }
    return buffer.length === 0;
}

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Nolgthorn posted:

Not in test cases, therefore not my problem.

In honesty 90% of a technical interview is seeing how you solve/iterate on problems. So add test case and fix.

An excellent answer for the coveted “junior engineer with no hope of advancement and yet still has a chip on their shoulder” position.

xtal
Jan 9, 2011

by Fluffdaddy
bad code here

xtal fucked around with this message at 15:59 on Jun 18, 2019

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
Given a string, make sure every "Fizz" is matched with a "Buzz"

FlapYoJacks
Feb 12, 2009
Yep, after the last page or so, I am now 100% in the impostor syndrome camp again. :smith:

CPColin
Sep 9, 2003

Big ol' smile.
To be fair, I'm not exactly sure what among my experiences led me to think "stack!" so quickly, so :iiam:

VikingofRock
Aug 24, 2008




ratbert90 posted:

Yep, after the last page or so, I am now 100% in the impostor syndrome camp again. :smith:

Don't be. You can be a great programmer and still be bad at or intimidated by the typical interview questions. Just because some people are very good at interview questions doesn't make them a better or more competent programmer than you.

Cuntpunch
Oct 3, 2003

A monkey in a long line of kings

ratbert90 posted:

Yep, after the last page or so, I am now 100% in the impostor syndrome camp again. :smith:

I know a developer who, after spending 3+ years working purely in C#, would still copypaste StackOverflow answers written in java - without realizing it was a different language - and then lose an entire day of work trying to figure out why the compiler kept bitching about the @SomeAttribute poo poo in his code, despite it CLEARLY working in the answer.

So if you're able to read a given piece of contextless code and realize whether or not it's even written in your use-case language. You're already doing better than *some* people who make a living developing software.

VikingofRock
Aug 24, 2008




CPColin posted:

To be fair, I'm not exactly sure what among my experiences led me to think "stack!" so quickly, so :iiam:

It's probably because stacks are a good guess for a lot of interview-style questions. My typical thought process is roughly

  • Can I process this in a way where I only care about the most / least recent value? If so try a stack / queue
  • Do I need to instead look at all previous elements in some other order? Try a heap
  • Do I just need to determine if something was seen before? Try a hash set
  • Do I need to establish some sort of associative relationship between two things? Try a hash map

IME you can get pretty far just based on that + explaining your thought process as you go + some experience with these sorts of questions + being lucky enough not to be someone who freezes up during interviews.

NtotheTC
Dec 31, 2007


The real takeaway from all this is that if enough of these bloody top-tier tech companies need brackets parsed so desperately there's a decent usecase for a domain-specific language. So just write one of those and then smugly produce the source code in your interview.

xtal
Jan 9, 2011

by Fluffdaddy

NtotheTC posted:

The real takeaway from all this is that if enough of these bloody top-tier tech companies need brackets parsed so desperately there's a decent usecase for a domain-specific language. So just write one of those and then smugly produce the source code in your interview.

Unfortunately that didn't work for the Homebrew guy

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Ola posted:

I have such an interview tomorrow, so I had a go in JS. Shred me.

code:
function balanceBrackets(string){
  var brackets = {'}':'{',']':'[',')':'(','>':'<'};
  var stack = [];
  for (var c in string){
    if ('{[(<'.includes(string[c])){
      stack.push(string[c]);
    }
    if (')]}>'.includes(string[c])){
      var t = stack.pop();
      if (typeof t == undefined || t != brackets[string[c]]){
        return false;
      }
    }
  }
  return stack.length==0;
}
code:
balanceBrackets("{$$[fdasfsa<fdaf>####]%@#}")
true
balanceBrackets("{$$[fdasfsa<fdaf>####]%@#}(")
false
balanceBrackets("{$$[ff}fff]")
false

Just use !t jeez :rolleye:

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice
code:
#define LEFT_CURLY_BRACE "{"
#define RIGHT_CURLY_BRACE "}"
...

ToxicFrog
Apr 26, 2008


CPColin posted:

To be fair, I'm not exactly sure what among my experiences led me to think "stack!" so quickly, so :iiam:

Probably because when discussing language theory, "balanced brackets" is the example that every single professor and textbook likes to roll out first when talking about nonregular languages, almost always with a note that you need at least a pushdown automaton for them. The "balanced brackets" -> "stack" association is ubiquitous.

Nolgthorn
Jan 30, 2001

The pendulum of the mind alternates between sense and nonsense

Cuntpunch posted:

I know a developer who, after spending 3+ years working purely in C#, would still copypaste StackOverflow answers written in java - without realizing it was a different language - and then lose an entire day of work trying to figure out why the compiler kept bitching about the @SomeAttribute poo poo in his code, despite it CLEARLY working in the answer.

So if you're able to read a given piece of contextless code and realize whether or not it's even written in your use-case language. You're already doing better than *some* people who make a living developing software.

I worked with a guy who was convinced he improved Javascript with a horrendous utils directory. He obfuscated everything you could do in Javascript, if statements, filter, map everything, to the point where no code anywhere was anything more than function calls within function calls all the way down.

He was absolutely certain that it was superior to vanilla Javascript and wouldn't listen to a drat soul who told him to stop doing it. He worked at the company for like a year driving everyone insane.

Nolgthorn fucked around with this message at 21:36 on Jun 18, 2019

FlapYoJacks
Feb 12, 2009

VikingofRock posted:

Don't be. You can be a great programmer and still be bad at or intimidated by the typical interview questions. Just because some people are very good at interview questions doesn't make them a better or more competent programmer than you.

My specialty is embedded Linux systems engineering. I am more used to poking registers and doing some python or C++ stuff as well. Simple things like bracket parsing is apparently too advanced for my broke brain.

Nolgthorn posted:

I worked with a guy who was convinced he improved Javascript with a horrendous utils directory. He obfuscated everything you could do in Javascript, if statements, filter, map everything, to the point where no code anywhere was anything more than function calls within function calls all the way down.

He was absolutely certain that it was superior to vanilla Javascript and wouldn't listen to a drat soul who told him to stop doing it. He worked at the company for like a year driving everyone insane.

So Jquery?

Phobeste
Apr 9, 2006

never, like, count out Touchdown Tom, man
Yeah isn’t that just normal npm

Adbot
ADBOT LOVES YOU

qntm
Jun 17, 2009

Nolgthorn posted:

I worked with a guy who was convinced he improved Javascript with a horrendous utils directory. He obfuscated everything you could do in Javascript, if statements, filter, map everything, to the point where no code anywhere was anything more than function calls within function calls all the way down.

He was absolutely certain that it was superior to vanilla Javascript and wouldn't listen to a drat soul who told him to stop doing it. He worked at the company for like a year driving everyone insane.

Oh hey, let's trade dreadful JavaScript "utility functions". I'll go first:

JavaScript code:
/**
 * @param partialMatch: string 1 "fun" will match string 2 "funny". String1 "funny" will not match
 * String2 "fun"
 */
function strCompare(string1, string2, partialMatch, ignoreCase)
{
    if (ignoreCase)
    {
        string1 = string1.toLowerCase();
        string2 = string2.toLowerCase();
    }
    if (partialMatch)
    {
        return (string2.indexOf(string1) > -1);
    }
    return (string1 === string2);
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply