The Big Programming Thread - Page 859
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Nesserev
Belgium2760 Posts
| ||
netherh
United Kingdom333 Posts
On March 10 2017 07:03 Nesserev wrote: I don't see how you could write any decent code under 5 minutes to solve this problem. Yeah. Took me about 15 minutes to create a basic solution and realise it didn't work, 30 minutes of trying to remember how reverse_iterators work (yay C++), and another 15 minutes of fiddling around and fixing edge cases. Googling shows there are better ways of doing this (and would be the first step anywhere other than interviews I guess...). + Show Spoiler +
| ||
slmw
Finland233 Posts
| ||
Khalum
Austria831 Posts
I'm curious why the string as well as the length are valid outputs. The approach is the same? | ||
meatpudding
Australia520 Posts
def palin(s): Output: 7 racecar I only just realised that this will only work for odd palindromes. | ||
![]()
tofucake
Hyrule18969 Posts
making it support an array and finding the longest palindrome of the bunch is another 2 minutes :\ | ||
Hanh
146 Posts
| ||
Deleted User 3420
24492 Posts
pretty sure this is O(n) unless we are dealing with the longest strings of all time I didn't record the actual string because blisse said I didn't have to. but I could if I needed to it would just be a very mildly painful addition edit: I guess slmw was talking about beating O(n^2) per word, which makes more sense because why would you have to iterate through words more than once So looking at the complexity of this per word... mmmm.. I really am not sure? I guess it's technically O(n^2) but it's like a really good O(n^2), and that's worst case. maybe someone who is good at complexity could look at this and tell me what the complexity per word is? | ||
slmw
Finland233 Posts
On March 10 2017 10:18 Khalum wrote: I'm curious why the string as well as the length are valid outputs. The approach is the same? It's just basically a matter of formatting the output. On March 10 2017 10:43 tofucake wrote: I just had an interview today with a palindrome question. In JS it takes about 30 seconds to read the instructions, think, then type out
making it support an array and finding the longest palindrome of the bunch is another 2 minutes :\ You gotta still create all the substrings though so a bit more programming left to do!. Also this is O(N^3) per word! On March 10 2017 11:24 travis wrote: This is what I did. took 15-20 min cuz i kept making stupid mistakes
pretty sure this is O(n) unless we are dealing with the longest strings of all time I didn't record the actual string because blisse said I didn't have to. but I could if I needed to it would just be a very mildly painful addition edit: I guess slmw was talking about beating O(n^2) per word, which makes more sense because why would you have to iterate through words more than once So looking at the complexity of this per word... mmmm.. I really am not sure? I guess it's technically O(n^2) but it's like a really good O(n^2), and that's worst case. This is O(N^2) per word, but doesn't it work just for odd palindromes? https://ideone.com/ke4q0k | ||
Deleted User 3420
24492 Posts
![]() looking up i probably did whatever meatpudding was doing tbh I never even realized it was a palindrome if it wasn't odd, lol. the problem would be a million times harder for me including even palindromes basically I'd be writing all separate code to handle even palindromes ![]() it'd still be O(n^2) though | ||
WarSame
Canada1950 Posts
| ||
ShoCkeyy
7815 Posts
| ||
Hanh
146 Posts
On March 10 2017 11:38 travis wrote: oh duh of course it only works for odd palindromes ![]() looking up i probably did whatever meatpudding was doing tbh I never even realized it was a palindrome if it wasn't odd, lol. the problem would be a million times harder for me including even palindromes basically I'd be writing all separate code to handle even palindromes ![]() it'd still be O(n^2) though Don't worry too much about performance. Focus on correctness first. There is no point in returning a wrong result quickly. Looking back at this thread, the people who talk about how easy the question is have yet to give a good answer. | ||
Manit0u
Poland17187 Posts
On March 10 2017 14:11 WarSame wrote: Do any of you know a good place to go for code review? I want to have my git repo checked to see if there are better coding decisions I could have made. Is there some sort of dedicated area or site for that? What language? I love code reviews ![]() | ||
Cynry
810 Posts
I've been working for almost 2 years with mongo in js without an issue, but ever since I started go every single query that I have to do is a pain in the ass. It's my first project in go, soooo todolist it is ! And here's the query that is driving me nuts lately: func (u *User) getNextTask(date time.Time) (Task, error) { Simply receives a date, get the tasks that have been created after, sort them by ascending order to get the next one, limit to one result, etc. It doesn't even get here anyway. The query doesn't return anything, although everything I've checked is correct. I receive a proper date, u.Tasks does contain an array of bson.ObjectIds (the query works when I remove the timestamp part, so this is fine). There is at the moment of the tests, at least a task that has should match the query (same user, created after, can be checked if I do the same query without the timestamp part). So it apparently comes from that very line "timestamp": bson.M{"$gte": date}, but I can't see what's wrong with it. At this point I suspect a typo or something silly like that, but I seem to need an exterior look... So, anyone ? Palindrome challenge: All I could come up in 5 minutes was some pseudo code that didn't work for odd palindromes... forgot about those ^^ | ||
Khalum
Austria831 Posts
On March 10 2017 15:05 Hanh wrote: [..] Looking back at this thread, the people who talk about how easy the question is have yet to give a good answer. Fair point! I had just come home from a night of drinking and would definately not have given a good answer then ![]() Am still a bit drunk but I gave it a shot to put my money where my mouth was. My solution is probably not correct. I hacked it in 7 minutes (yes, more than 5...) so I guess I failed anyways. Now back to sleep.
[edit] This is missing a function that calls getLongestPalindrome() with some strings to be tested and collects the max of these. [edit2] Fixed 2 errors. Yes, I cheat. | ||
netherh
United Kingdom333 Posts
On March 10 2017 14:11 WarSame wrote: Do any of you know a good place to go for code review? I want to have my git repo checked to see if there are better coding decisions I could have made. Is there some sort of dedicated area or site for that? Well there's this: http://codereview.stackexchange.com/ I think you're supposed to include code in the question though, so depends on how large your repo is, or if you can extract specific bits of code. | ||
Deleted User 3420
24492 Posts
I want to pass a char pointer to a function. Then go through the memory, and find integers. Store those integers into a character array. And then return the pointer to the new character array (that only holds the integers). But because my character array is local to the function it becomes garbage when my function ends, so this doesn't work But I am not supposed to use dynamic memory allocation, and im not supposed to use global variables so how do I do what I am describing? edit: is what I need to do, to declare my character array before i call my function, and then pass a pointer to it to my function? god I hate C | ||
slmw
Finland233 Posts
| ||
waffelz
Germany711 Posts
On March 09 2017 05:57 Nesserev wrote: Have you checked out qemu yet? (http://www.qemu-project.org/) I haven't, but I will check it out, Thanks for the suggestion. | ||
| ||