"Want me to write a specialised API with custom encapsulation transmitted over UDP?"
"Nah fam, we want to watch you code in our super-duper-wiz-bangy-exclusive IDE that you've never used before. Oh, and you have an hour. Oh, and it's going to be super-specific tasks that only we know how to do."
"So, no on the encapsulation, eh?"
<click>
What you’re describing is the opposite - some kind of esoteric question related to a specific language.
Of course, data.table has existed for over a decade and you're not going to come up with something comparable in 15 minutes, but that's why you'd want to just copy it and not come up with your own solution in the first place.
But then, when I interview, I don't ask leetcode questions in the first place...
- read file
- start at beginning; if you encounter separator, add new entry to an array. if you encounter newline, save entire current array as a new line to an array of lines.
- do lexicographical sort of arrays (can just use qsort for this).
- if the test q actually wants you to parse out numbers and shit like that, nothing about the structure changes, you just have to record some extra info when parsing values and then use a different comparison depending on the type in the function you pass to qsort
I dare say someone programming algorithms in a kernel or writing code for custom file systems should be able to do this. OK 15 min may be tight if you're nervous but you should get there.
Things get even weirder when you throw non-Latin characters in the mix. May such parsers predate widespread use of UTF-8.
Personally I’d do it by storing indexes into the CSV contents instead of using null terminated C strings.
Doing all of this in just 15 minutes is going to be hard.
By the way, your solution as described is wrong, since it sorts each row independently. What you’d need to do is store all the data in a transposed format i.e an array of pointers to column arrays, then sort the array by giving qsort a comparison function that looks at the first entry in each column.