I had a test this Tuesday; I failed. Three problems, all array related. A 45 minute time limit.
The first one asked in some fancy wording to basically return the range of consecutive indexes of the highest streak of integers. e.g [90, -100, 45, 3, -56, 529, -190, 200, -10] should return [5, 7] (five to seven, inclusive). This thing took me like 20 minutes to solve. Which I find ridiculous, it looks so easy now. Later I found out I didn't get full credits because my solution didn't pass all of the test cases.
The second problem asked to combine and sort two arrays of integers, without copying or modifying the original arrays and without using tools from any libraries. e.g given arrays [5,1,3] and [4,2,6] I should return [1,2,3,4,5,6]. This is the only one that I got right.
The last problem I thought very simple at first sight but for the life of me I couldn't solve it before running out of time. It required to return the elements of an array in a certain order: given the array ['a', 'b', 'c'] my function should return: [ ['a'], ['a', 'b'], ['a','b','c'], ['a', 'c'], ['b'], ['b', 'c'], ['c'] ]
I decided never to let that happen again. Array problems have always been my weakness. In general, any kind of timed problem solving exercise makes me uneasy. I hate to admit it but I am a slow thinker. I marvel at the way others can come up with solutions so fast when I'm barely starting to dissect the problem into pieces.
IMO, there can only be three possibilities to this: either they're geniuses, they have been exposed to similar problems before so they have a general idea on how to approach it, or I have a turd for a brain and I should sever my testicles so I don't perpetuate my diluted genes onto my offspring.
Whatever the case is, there's nothing I can really do about it except to prepare. So that next time I don't have to reinvent the wheel but merely load the potato sacks into the cart and giddy-up Matilda.
After giving it some thought, I believe array problems can be categorized into two types: Sort and Lookup. Sorting problems require the array to be sorted in a specific way: ascending, descending or by some arbitrary parameter. Lookup problems require you to select specific values from the array., according to some rule.
I would like to know if you guys are aware of any good site with programming exercises related to this topic, or know of good books on the subject, no matter the language.
Thank you.