So I was looking at some reviews for a company I would like to work for- one of the reviews mentioned they took their interview questions from leetcode, so I took a peek.
I did a couple of their exercises, and one in particular was interesting to me.
https://leetcode.com/problems/valid-number/
Essentially the purpose was to validate a string that has an integer value. Easy street! Numbers are simple. Well their requirements were quite odd, and it led to several frustrating iterations, which felt unnecessary. For instance " -5" is a number but " - 5" is not a number, but there were no written guidelines indicating leading or trailing spaces should be ignored while inner spaces should be invalid. No big deal, got it figured out, moved on to the next logical question:
https://leetcode.com/problems/string-to-integer-atoi/
A custom atoi.
Now this one is much more fun! Normally I would use stringstream, but the requirements from the last batch were strange, so the requirements for this one ought to be strange too right?
So naturally I spent a bit and wrote a function (which is quite handy anyways) that converts a string that has any integer style value to that value (so
0x55
,
12e-9
,
-.55
, the works!)
I was a bit miffed when the requirements were nothing more than +-xxxxxxxxxxxxx but at least I got a useful function out of the deal!
It led me to thinking about a couple things. Is there a database of self contained functions somewhere online? Maybe a website that you can type a few key search words and get a list of functions tagged with them?
For instance, I wrote a little json/xml/csv conversion class/function set- I don't really want to release a library, and I would feel a bit silly releasing it on my website or github, but it would be great to submit it to a big free function database or something!
Obviously we have sites like this and stackoverflow and the other QA sites. All of which are logical places. It would be really nice to have just code somewhere though!
Anyone know of a site like that? I may just go ahead and make it myself if it doesn't exist, but I like minimizing duplicated efforts (I suppose that's obvious)