

Hacker CS: Computer Science Challenges - agilo
http://hackercs.com/streams/Computer-Science-Challenges/

======
masterj
My take on in-place reversing words in a string. Would appreciate any
suggestions for improvement :)

    
    
        #include <string.h>
        
        void reverseRange(char *i, char *j) {
            char temp;
            for (--j; i <= j; ++i, --j) {
                temp = *i;
                *i = *j;
                *j = temp;
            }
        }
        
        
        void reverseString(char *str) {
            char *ptr;
    
            // reverse the whole string
            reverseRange(str, strchr(str,'\0'));
            
            // reverse each individual word
            for (ptr = str; *ptr; str = ptr + 1) {
                for (ptr = str; *ptr != ' ' && *ptr; ++ptr) {}
                reverseRange(str, ptr);
            }
        }

~~~
cpeterso
Looks good. reverseRange()'s end condition can just be `i < j` because you
don't need to swap the middle character with itself. :)

~~~
masterj
Doh! Somehow I got that mixed up in my head because that was my original
intention. Thanks!

------
mtogo
Looks interesting, but i'm really starting to get annoyed at the overuse of
the word hacker.

------
spaghetti
Bored at work so I thought I'd try this one: "First non-repeated character in
a string":

char firstNonRepeatedChar(string s){

    
    
        HashTable H;
    
        foreach(char c in s) H[c]++;
    
        foreach(char c in s) if(H[c] == 1) return c;
    }

~~~
kenjackson
If you're still bored, what if the alphabet is small (say 26 characters), but
string is typically huge (billions of characters) -- and on average the first
repeated character is in the middle of the string. How does that change your
algorithm?

~~~
idunno246
It couldn't average in the middle, right? You're guaranteed one in the first
27(alphabet+1) characters, so just do it on that substring

~~~
kenjackson
What if most of the strings look like:

"abcabcabcabc....abcabcxabcabcabcabc...abcabc"

------
laconian
Meh, this looks like a short list of Glassdoor interview questions. Here's the
real deal: <http://projecteuler.net/>

~~~
CountHackulus
The difference between this and Project Euler is that Project Euler is far
more math focused. Once you get past the first couple dozen problems you're
just looking for a math trick to make the brute forcing easier.

These challenges actually seem to test your knowledge of programming, not
mathematical identities.

------
iqster
I like the look of the site! Good job.

QQ .. In the very first video on Linked Lists, is the Node type defined
correctly? Shouldn't next be a pointer to Node?

~~~
bm1362
The site, unfortunately, does not look good-IMO that would be the last way I
would describe it. The videos are amazing though, good job.

