I originally posted this post on my blog.
Did AI kill the tech interview?
Truth is hiring and interviewing have been broken for years. There wasn't much left to kill.
In over 10 years, I've witnessed all types of interviews: casual conversations, interrogation-like conversations with rapid-fire questions, take-home coding exercises, and the infamous LeetCode exercises.
I asked Phind and Copilot to solve an interview exercise. I might or might not have been asked that exercise when applying to a FAANG.
Here's the "made-up" problem:
You're given a string containing the words "one" and "two", and the symbols "+" and "-" representing a math expression. Write a C# function called "Evaluate" to evaluate that expression after replacing "one" with 1 and "two" with 2. Assume the underlying expression is well-formed. For example, "one+one" should return 2, "two-two-one-two" should return -3, and "one+two-one-one+two+one" should return 4.
I'm using that exact same problem statement as a prompt for both Phind and Copilot. I know...I could have a more advanced prompt.
In this corner, with over 10 years of C# experience, me:
Here's my "pure string evaluation" solution:
private int Evaluate(string str)
{
var first = str[..3];
var result = first == "one" ? 1 : 2;
var index = 3;
var lastOperation = '+';
while (index < str.Length)
{
var substring = str.Substring(index);
if (substring.StartsWith('+'))
{
lastOperation = '+';
index++;
}
else if (substring.StartsWith('-'))
{
lastOperation = '-';
index++;
}
else if (substring.StartsWith("one"))
{
result = lastOperation == '+' ? result + 1 : result - 1;
index += 3;
}
else if (substring.StartsWith("two"))
{
result = lastOperation == '+' ? result + 2 : result - 2;
index += 3;
}
}
return result;
}
OK, that's ugly and has lots of repetition.
I looped through the string to identify if I was visiting a number or a symbol and stored the last known number and operation.
Nothing fancy! Probably I wouldn't have hired myself with that solution. But, hey, "it works on my machine."
And, let's see what Phind and Copilot do. Place your bets...Drum rolls...
In this corner, with its "largest and most performant model to date," Phiiiiind:
Here's Phind's exact solution (here's my conversation but I don't know how long it's stored though):
public static class WordNumberEvaluator
{
private const string ONE = "one";
private const string TWO = "two";
/// <summary>
/// Evaluates a mathematical expression containing word numbers 'one' and 'two'.
/// </summary>
/// <param name="expression">The expression to evaluate</param>
/// <returns>The numerical result of the expression</returns>
public static int Evaluate(string expression)
{
// Replace word numbers with digits
string processed = expression
.Replace(ONE, "1")
.Replace(TWO, "2");
// Use DataTable.Compute to evaluate the expression
var dataTable = new DataTable();
var result = dataTable.Compute(processed, String.Empty);
return Convert.ToInt32(result);
}
}
public class Program
{
public static void Main()
{
Console.WriteLine(WordNumberEvaluator.Evaluate("one+one")); // Outputs: 2
Console.WriteLine(WordNumberEvaluator.Evaluate("two-two-one-two")); // Outputs: -3
Console.WriteLine(WordNumberEvaluator.Evaluate("one+two-one-one+two+one")); // Outputs: 4
}
}
Phind surprised me a lot.
- It used a
DataTable
to evaluate expressions. I didn't knowDataTable
could do that. I wouldn't have thought about that in a real interview. - It added docstring comments and two comments to explain its solution.
But that didn't surprise me as much as seeing all the tests turning green when I ran its solution. For a moment, I thought using a DataTable
was a hallucination. A veteran coder warned me about them the other day.
If you're still skeptical, like me when I saw that function working, here's Microsoft official docs on DataTable's Compute method. It's more Excel-like formulas inside a DataTable
. The first parameter is an expression and the second one, a filter.
OK, the thing was Phind referenced 4 sources. Two of them were Medium posts talking about evaluating math expressions, but nothing inside them related to the solution it used.
And in this corner, backed by Microsoft, Copiiiiilot:
Here's Copilot's solution:
using System;
using System.Data;
class Program
{
static void Main()
{
Console.WriteLine(Evaluate("one+one")); // Output: 2
Console.WriteLine(Evaluate("two-two-one-two")); // Output: -3
Console.WriteLine(Evaluate("one+two-one-one+two+one")); // Output: 4
}
public static int Evaluate(string expression)
{
// Replace "one" and "two" with their numeric equivalents
expression = expression.Replace("one", "1").Replace("two", "2");
// Use DataTable to evaluate the expression
DataTable table = new DataTable();
return Convert.ToInt32(table.Compute(expression, string.Empty));
}
}
OK, I used Copilot on a browser, not inside my Visual Studio or Visual Studio Code. Same trick with DataTable
. I wasn't impressed the second time.
Not even in my dreams, (and I don't dream about code) I would have thought about using DataTable
as the trick under my sleeve here, especially with a clock-ticking on a platform like LeetCode or with a hiring manager looking at my screen.
Did AI kill the tech interview? I'd say yes, at least for data structure and algorithm questions. OK, I only tried it with one coding exercise, but that's still a yes.
Join my email list and get a short, 2-minute email with 4 curated links about programming and software engineering delivered to your inbox every Friday.
Top comments (15)
I don't know anything about
DataTable
(not a C# developer), but my first question would be what the performance difference is between the two (your solution, and Phind's).My second question would be about the size of the compiled program.
An "elegant" solution is not always the best.
Those are interesting questions Dan. I didn't take the time to run benchmarks, I was surprised enough that I rushed to write about it :)
Ohhh! Good point!
Awesome
This is my solution in JavaScript (before reading the rest of your post):
This is what I call a "quick and dirty solution". I'd have felt guilty because of using
eval()
(yeah, never a good idea), but then I'd have remembered that this was an exercise for a stupid interview, and I would have handed in as it was.Only later I realized that I was supposed to use C#. In my case, I'd have used Roslyn in order to evaluate the solution, I suppose.
That gets all the tests turn green...With a clock ticking, my quick and dirt solution was a string processing solution, parsing each character, it only made me waste time. :\
Okay, the preprocessor solution (I could not resist, I guess):
It's again JavaScript, but used more like Java, so I think it is recognizable.
As you can see, I would anyways replace "one" with 1 and "two" with 2... it simplifies things.
I use an
isInt()
function. This is an entrypoint for a hypotetical solution with numbers of any width (not only 1-digitint
s). This nearly does not add complexity to the solution, and I think it makes it more robust. Just a little bit of overengeering tradeoffI also don't like that
char
0 being the starting status, so I coded with the last operation being add as default, and the value to return 0.My two cents.
...I also feel a little bit hurt about my post about AI, or my reputation, were not enough for you, and you had to ask a veteran...
[This is a joke. Yep, I'm that stupid. :-P ]
Wow, I never would've reached for DataTable.Compute in an interview either. Do you think these kinds of shortcuts actually make the hiring process any better, or just weirder?
It makes the hiring process weirder for both sides. From candidates using AI to lip sync to companies expecting fully functional solutions for take-home exercises.
Man, learning that DataTable trick after all these years kinda blew my mind - always stuff hiding in plain sight.
For a moment, I thought it was a hallucination. I had to double check and run the code on my side just to convinced me it was right. Blew my mind too, so I had to write this post.
Fascinating how both models landed on the same creative solution...
yeah, it wasn't that surprising the second time I saw the DataTable trick :\
AI dev tools are getting wild lately - sometimes they impress, sometimes they hallucinate like it’s jazz night. Curious to hear what surprised you most!
The solution with the DataTable really surprised me. (That was what mad me write this whole post.) That's something we wouldn't come up with unless we had devoured the official docs or ran into an issue.