![]() |
C++ Coding Challenges
I have been learning C++ for over a year now and I would like to ask the community for some C++ coding challenges or puzzles. My professors have given me ones such as ...
int strlen(char * sz) { } note: solution only took 3 lines using (recursion) OR "Write a C function that multiplies an input integer by 5 and returns the result. The function must not use the multiplication operator. Optimize for speed." I believe this one actually goes into the bits. Anyways, I wonder if you could share some of yours in hopes of challenging others. |
http://www.codechef.com/
Up top you'll see a "Practice" tab which will provide problems to solve. There are even competitions in which you can enter. It's a great site. |
Here is a whiteboard C coding question I was asked at an actual game company interview. Complete this function:
Code:
bool IsPalendrome(char* str) |
Try the demo test on http://codility.com/
|
Quote:
|
The free demo test itself is usually pretty decent. Codility is for the hiring managers to sends tests out rather then preparing for interviews.
|
Quote:
I saw this last night while browsing, and it's a nice little problem, if not especially taxing. As a novice, I originally thought it would be best to break it down into an array and do something complicated such as reversing the order of the array and then comparing them. But there is no need - after further reading, having seen the string tools available. Once I was thinking along those lines, it took about 20 mins. So here's a solution (in python rather than C) - anyone got any optimisation tips? Code:
#!/usr/bin/python |
As for "optimizations", instead of, "while j > 0", you could use, "while j > length*.5", since you've already checked the first n/2 letters of the word. :P
(I might be off by one. Sorry for that, if so.) |
Quote:
Code:
int strlen(char * sz) |
Well, depends on the definition of optimization:
Code:
def isPalindrome(string):Quote:
|
| All times are GMT -8. The time now is 03:15 PM. |
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.