> that leaves me with 1 and 5...
>
> Is there a simple way to short cut these tests in C#?...it would be
> pointless me setting a test only to find it was trivial...or required a
> trick....rather than demonstrating ability.

char[] chars = "foo".ToCharArray();
Array.Reverse(chars);
string reversed = new String(chars);

haven't tested it, but looks like the way to do it. So fairly trivial... that
is, if you have the BCL docs available. From someone's bare head it will
likely end up with a loop, unless the person doesn't know that string[index]
is possible... however, is that vital knowledge?

5 is a bit tougher but is also doable in an O(n) algo of a couple of lines and
a hashtable. (if with 'longest run' is meant: "aaabbbbbbbcccaaaa" the longest
run is "bbbbbbb". Again, this builds on the knowledge of string[index] returns
a char (ok, you can get away with it with Substring(), but nevertheless, it is
a lowlevel string voodoo trick, clearly a C-pointer question.

Another nice test, but meaningless:
Given a list of objects which have an ID field and a ParentID field (which can
be null (one of them)), write a piece of code which builds the complete
graph/tree from the objects in an O(n) algo. (O(2n) actually, but you may
ignore constants in that O notation.

as said, ask something in the line of the job. That's more appropriate.

        FB

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to