Open Side Menu Go to the Top
Register
Interview  Test Questions Problems, Solutions, Links, Discussion Interview  Test Questions Problems, Solutions, Links, Discussion

09-26-2016 , 06:01 PM
I gave DaveT's question as a 1-ish hour take home assignment for a job intervewee for a node position today (we had no way to share screens to whiteboard). He returned it in under and hour... in C#.

Then when I made it clear I wanted the answer in JS - as that's the position he's applying for - all of a sudden his day was too busy for that. Also he had some fun stuff on his resume - like he was working in angular and react in 2014 for a large bank. Riiiiiggght.

So here's his reply. Seems pretty brute force/standard, but at least it works (someone else ran it and confirmed for me). C# experts please weigh in if you want to.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
   class Program
    {
        static void Main(string[] args)
        {
           
            int[,] arr = new int[,] { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 }, { 17, 18, 19, 20 } };
            int rowLength = arr.GetLength(0);
            int colLength = arr.GetLength(1);
            for (int a = 0; a < rowLength; a++)
            {
                for (int b = 0; b < colLength; b++)
                {
                    Console.Write(arr[a, b] + "\t");
                }
                Console.WriteLine();
            }
            Console.WriteLine("Output Is:");
            //Taken m*n matrix 5*4
            int m = rowLength;
            int n = colLength;
            int i; int k = 0; int l = 0;
             m--;
             n--;

            while (k <= m && l <= n)
            {
                // It prints the row left to right up to column length 
                for (i = l; i <= n; ++i)
                {
                    Console.Write(arr[k, i]+" ");
                }

                // Prints the column top to bottom
                k++;
                for (i = k; i <= m; ++i)
                {
                    Console.Write(arr[i, n]+" ");
                }

                // Prints the row right to left
                n--;
                if (m >= k)
                {
                    for (i = n; i >= l; --i)
                    {
                        Console.Write(arr[m, i]+" ");
                    }
                    m--;
                }

                // Prints the column bottom to top
                for (i = m; i >= k; --i)
                {
                    Console.Write(arr[i, l] + " ");
                }

                l++;
            }

            Console.ReadLine();
        }

    }
}
I grilled him a little about how he'd do it in JS and he just mumbled some buzzwords. I specifically asked him what built in JS array functions he might use to reduce code complexity, and he had nothing.

jquery came up a lot in his interview, so I think he at least knows his way around that. Oh yeah - also he couldn't name the server they run JSPs on at his last job. Like he didn't seem to know what a webserver is. So yeah that plus no JS = GREAT candidate for node job.

Also he said they were using stored procedures over C++ to access mongodb from node. I guess it's theoretically possible someone wrote some weird-ass stored proc simulator. Any attempts to drill down further were just met with buzzwords like "single-threaded" and "highly-scalable".

Now maybe you guys understand why we take anyone with a hint of being a good programmer. Otherwise you're just interviewing people like this until the end of time.

Last edited by suzzer99; 09-26-2016 at 06:07 PM.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-26-2016 , 10:22 PM
Quote:
Originally Posted by suzzer99
I gave DaveT's question as a 1-ish hour take home assignment for a job intervewee for a node position today (we had no way to share screens to whiteboard). He returned it in under and hour... in C#.
I don't think he wrote this himself btw. It looks like a vague copy of this:

http://www.geeksforgeeks.org/print-a...n-spiral-form/

I would try to avoid giving known algorithm problems in a takehome assignment for this reason.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-26-2016 , 11:21 PM
Funny, I was working on the spiral problem today.

Here my code. Started off writing it in google doc. Submitted to leetcode but then my solution wasn't working when the column or row were equal to 1. So I had to add some weird checker as the base case...

I'm not exactly proud of this. Going to look at geeksforgeeks.

Code:
class Solution {
public:
    vector<int> spiralOrder(vector<vector<int>>& matrix) {
       
        vector<int> answer;

        if (matrix.empty()) return answer;

        recurse(matrix, 0, 0 , matrix[0].size(), matrix.size(), answer);
        return answer;

    }

   void recurse(const vector<vector<int>> &matrix, int row, int col, int cLen, int rLen, vector<int>& answer) {
                if (cLen <= 0 || rLen <= 0) return;
                
                if (cLen == 1) {
                    for (int r = row; r < row + rLen; r++) {
                        answer.push_back(matrix[r][col]);
                    }
                    
                    return ;
                }
                
                if (rLen == 1) {
                    for (int c = col; c < col + cLen; c++) {
                        answer.push_back(matrix[row][c]);
                    }
                    
                    return ;
                }

               //go full length across      
                for (int c = col; c < col + cLen; c++)
                answer.push_back(matrix[row][c]);

              //go row+1 downto rLen + row
              for (int r = row + 1; r < row + rLen; ++r)
                  answer.push_back(matrix[r][col + cLen - 1]);

             //go last col - 1 down to col
             for (int c = col + cLen - 2; c >= col; --c)
                  answer.push_back(matrix[row+rLen -1][c]);

            //go last row - 1 up to row + 1
             for (int r = row + rLen - 2; r >= row + 1; r--)
                   answer.push_back(matrix[r][col]);

            recurse(matrix, row + 1, col + 1, cLen - 2, rLen - 2, answer);           
   }
};
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 12:05 AM
Quote:
Originally Posted by candybar
I don't think he wrote this himself btw. It looks like a vague copy of this:

http://www.geeksforgeeks.org/print-a...n-spiral-form/

I would try to avoid giving known algorithm problems in a takehome assignment for this reason.
Sheesh. What a putz. Now he's begging for a job over email.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 12:38 AM
Also if you can't screen share you should do a google doc and just be over the phone. Having the candidate write something up and have him/her not show you the thought process makes it kind of useless.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 12:42 AM
Well the idea was to have him explain the thought process, but yeah if these ****ers are going to cheat. Wasn't my department or anything, I just got pulled in as the node expert. People just call me with node stuff and I try to help them. I have no idea who anyone is or even if it's in my job description to help them.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 06:41 AM
Suzzer, you can use this:

https://coderpad.io/

There are quite a few alternatives as well,

My knowledge of C# has waned a bit, but that's clearly hot garbage. Why do you need Linq (an SQL / data lib) or any of the other libs to do this?
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 10:12 AM
Quote:
Originally Posted by suzzer99
Sheesh. What a putz. Now he's begging for a job over email.
i dunno, something to be said for resourcefulness and persistence. he seems like he has promise.

btw, that c# code should yield the right results. though, its not nearly as cool as some of the other submissions itt. ofc, I have no clue wtf is going in candybars and it took me a bit figure out wtf that gaming mouse ramda thing was.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 12:28 PM
Quote:
Originally Posted by daveT
My knowledge of C# has waned a bit, but that's clearly hot garbage. Why do you need Linq (an SQL / data lib) or any of the other libs to do this?
I think that's what VS spits out when you create a new class. I don't bother removing that either.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-27-2016 , 04:03 PM
https://www.hackerrank.com/challenges/new-year-chaos

I'm curious what people think of this question.

Spoiler:

My initial attempt was very close to the solution but I then became convinced it was more complicated than I thought so I wasted an hour+ writing an ugly linked list O(n^2) type solution that worked but timed out for the big inputs.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-28-2016 , 06:20 PM
Quote:
Originally Posted by Prickly Pear
https://www.hackerrank.com/challenges/new-year-chaos

I'm curious what people think of this question.
I haven't actually tried it but I have an approach in mind, that I expect would be O(n) and not too hard to implement. It might actually only be a few lines of python. I am ****ing swamped but if I get some free time I might try it.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-28-2016 , 06:23 PM
But, I think you need to stipulate that there's no bribe-backs. Consider the case where you start with
1 2 3
and 3 bribes 2, now you have
1 3 2
and now 2 bribes 3, now you have
1 2 3

Which means that given the string 1 2 3 you could have 0, 2 or 4 swaps (I think those are the only possible ones for 3 people)

If there's no swapbacks then I think it should be straight forward.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-28-2016 , 06:57 PM
Quote:
Originally Posted by RustyBrooks
But, I think you need to stipulate that there's no bribe-backs. Consider the case where you start with
1 2 3
and 3 bribes 2, now you have
1 3 2
and now 2 bribes 3, now you have
1 2 3

Which means that given the string 1 2 3 you could have 0, 2 or 4 swaps (I think those are the only possible ones for 3 people)

If there's no swapbacks then I think it should be straight forward.
but it's asking for the min number, so it would be 0 in that case
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-28-2016 , 08:32 PM
OK it does say minimum, so, never mind.

My algorithm does not work if there are swaps back in the other direction. If I have some time I'll try to look at it soon.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-29-2016 , 10:18 PM
Pretty good interview question, I think.
Spoiler:
Recursion! The max integer needs to be in the final three positions (otherwise "too chaotic"); delete it (and add how many positions away from the end it is) and then continue. Only needing to check the final three positions both makes this O(N) and also takes care of the "too chaotic" bit.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 02:54 AM
Had my Boogle phone interview today. Not sure how I feel about the interview. But so far I haven't got a rejection yet so that's good. Spent a lot of time on big O analysis over one simple problem and many different approaches.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 04:07 AM
Quote:
Originally Posted by Prickly Pear
https://www.hackerrank.com/challenges/new-year-chaos

I'm curious what people think of this question.
Spoiler:

It seems logical that you should execute at the end and work your way back.

L = [2, 1, 5, 3, 4]

Finding "too chaotic" is pretty simple with the constraints:

Each number must be no more than 2 indices away from it's original position.

The next step, after establishing no chaos, is simply count the position of number and subtract it from where it would be under normal circumstances. In the above, 5 if is in L[-3] when it should be in L[-1] it is therefore, 2 bribes away since the difference between the indices is 2. The number 2 is in position -5 but should be in -4, thus it takes one bribe to get back to it's original position. Adding up the differences gives us 3. We can ignore 1, 3, 4 because they are going to push up. Maybe you can do a recursive pass to be sure, but I'm not entirely sure if this is needed because I'm not sure if people can leap frog each other.

Using the second input:

L = [2, 5, 1, 3, 4]

We see that 5 is not in L[-1] or L[-2], so it is too chaotic.

Without specifying whether leap frogging is allowed, I don't like this question to much. I mean, is this a valid input?

L = [2, 1, 5, 4, 3]
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 08:02 AM
Quote:
Originally Posted by daveT
Spoiler:

Without specifying whether leap frogging is allowed, I don't like this question to much. I mean, is this a valid input?

L = [2, 1, 5, 4, 3]
Spoiler:

It is, for example:
[1, 2, 3, 4, 5]
[1, 2, 3, 5, 4]
[1, 2, 5, 3, 4]
[1, 2, 5, 4, 3]
[2, 1, 5, 4, 3]
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 10:14 AM
Is this what you are attempting to describe?

Spoiler:
cnt = 0
[2, 1, 5, 4, 3], move 5 two pips, then remove

cnt = 2
[2, 1, 4, 3]; move 4 one pip, remove

cnt = 3
[2, 1, 3]; 3 is okay, remove

cnt = 3
[2, 1]; 2 is one pip; remove

cnt = 4
[1]
len L <= 1; done

return 4

***

if at any time the move is more than 2, too chaotic.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 10:22 AM
Spoiler:
Yup exactly. You just need to remove the number and keep track of the index contribution to the number of transpositions; if you can't find it among the last three indices at any step, it's "too chaotic".
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 10:23 AM
Then I have to say that's a pretty darn good interview question.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 10:53 AM
Agreed. There's one other thing that I like about this one:
Spoiler:
Handling the case when it's "too chaotic" is a nice extra point of discussion on the usual "one-line recursion" style interview questions (maybe even more so if it's a language where exceptions for control flow are considered problematic).
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 12:06 PM
I think if you're going to ask this question in an interview you need to have a hint ready, because I don't think I'd have come up with this on my feet. Or, I guess maybe I should accept that you wouldn't hire me.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
09-30-2016 , 12:18 PM
Quote:
Originally Posted by daveT
Spoiler:

The next step, after establishing no chaos, is simply count the position of number and subtract it from where it would be under normal circumstances.
Spoiler:
this was my first attempt and it works with their initial sample input

but it's wrong and fails for the other tests
Interview  Test Questions Problems, Solutions, Links, Discussion Quote
10-01-2016 , 04:14 AM
Quote:
Originally Posted by RustyBrooks
I think if you're going to ask this question in an interview you need to have a hint ready, because I don't think I'd have come up with this on my feet. Or, I guess maybe I should accept that you wouldn't hire me.
Yeah, give me matrices and I'm stumped. Give a strange recursion puzzler and I'll get to the answer eventually. I know damn well there are tons of algorithms that you'd destroy me on in an instant, but with a question like this, I'd definitely have hints.

Quote:
Originally Posted by Prickly Pear
Spoiler:
this was my first attempt and it works with their initial sample input

but it's wrong and fails for the other tests
Spoiler:
Yes, I started with the assumption that there was a specified order, but continuing down the train of thought, this is a recurrence problem, which will often dissolve into some reduction of the space via each step. Those were initial inductions, but close enough to get something useful started.

At least as I understand recurrences, start by proving the simple case first, like f(x) = 0, then f(x) = 1, devise a pattern and test. recur.
Interview  Test Questions Problems, Solutions, Links, Discussion Quote

      
m