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.