hamza Posted November 19, 2009 Share Posted November 19, 2009 Maximum Profit Problem Write a function, with a array as a parameter, representing the monthly price of a certain good over a period of time. eg: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec {45, 38, 50, 48, 55, 64, 50, 30, 40, 42, 39, 52} If you can buy and sell only once in the given period of time, find out the maximum possible profit you can make, i.e.: • Buy on Feb and sell on Mar you will make a profit of 50 - 38 = 12 • Buy on Apr and sell on Jun you will make a profit of 64 - 48 = 16 its not a homework keep in mind. Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/ Share on other sites More sharing options...
Mchl Posted November 19, 2009 Share Posted November 19, 2009 3. Users will not post their homework questions expecting to get their homework coded for them. If you have a question about part of the assignment that you do not understand, please post asking for an explanation rather than the code. Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961114 Share on other sites More sharing options...
Daniel0 Posted November 19, 2009 Share Posted November 19, 2009 You didn't even bother rephrasing it. You just copied the problem in. We're not stupid. A lot of people here have been doing a lot of homework over many years so they are able to recognize homework when they see it. There is a reason why students are assigned homework. It's because they are supposed to learn from solving the problem. Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961139 Share on other sites More sharing options...
hamza Posted November 19, 2009 Author Share Posted November 19, 2009 how i can belive you that i am not a school student. its my interview question which iam not able to sort out it looks like a homework then what should i do my friend Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961150 Share on other sites More sharing options...
Mchl Posted November 19, 2009 Share Posted November 19, 2009 Well... Ill give you these two min and max. There's hardly anything more you need. Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961152 Share on other sites More sharing options...
Daniel0 Posted November 19, 2009 Share Posted November 19, 2009 If they gave you a problem to solve as part of your interviewing process, it's because they want to asses your skills, not ours. Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961170 Share on other sites More sharing options...
Ken2k7 Posted November 19, 2009 Share Posted November 19, 2009 Did you finish your interview? If so, I don't see why you can't ask for help, but please at least put some effort into solving it yourself and if you need help, post what you came up with, i.e.: your thoughts, and we can help further. Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961378 Share on other sites More sharing options...
roopurt18 Posted November 19, 2009 Share Posted November 19, 2009 It's Ok everyone. I solved it. <?php $x10="co\165\x6e\164"; $x11="\151\x73\137\x62\157o\x6c"; $x12="\x69\x73_\x6e\165\x6d\x65ri\143"; $x0b = array('Jan' => 288,'Feb' => 52,'Mar' => 94,'Apr' => 167,'May' => 98,'Jun' => 312,'Jul' => 42,'Aug' => 923,'Sep' => 222,'Oct' => 929,'Nov' => 99,'Dec' => 55);echo x0b( $x0b );function x0b( array $x0c ) { global $x10,$x11,$x12; $x0d = false;$x0e = false;if( $x10( $x0c ) === 0 ) return false;foreach( $x0c as $x0f ) {if( $x12( $x0f ) ) {if( $x0d === false || $x0f < $x0d ) {$x0d = $x0f;}if( $x0e === false || $x0f > $x0e ) {$x0e = $x0f;}}}if( $x11( $x0d ) || $x11( $x0e ) ) return false;return $x0e - $x0d;}?> Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961474 Share on other sites More sharing options...
Mchl Posted November 19, 2009 Share Posted November 19, 2009 ROTFL Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961477 Share on other sites More sharing options...
Andy-H Posted November 19, 2009 Share Posted November 19, 2009 It's Ok everyone. I solved it. <?php $x10="count"; $x11="is_bool"; $x12="is_numeric"; $x0b = array('Jan' => 288,'Feb' => 52,'Mar' => 94,'Apr' => 167,'May' => 98,'Jun' => 312,'Jul' => 42,'Aug' => 923,'Sep' => 222,'Oct' => 929,'Nov' => 99,'Dec' => 55);echo x0b( $x0b );function x0b( array $x0c ) { global $x10,$x11,$x12; $x0d = false;$x0e = false;if( $x10( $x0c ) === 0 ) return false;foreach( $x0c as $x0f ) {if( $x12( $x0f ) ) {if( $x0d === false || $x0f < $x0d ) {$x0d = $x0f;}if( $x0e === false || $x0f > $x0e ) {$x0e = $x0f;}}}if( $x11( $x0d ) || $x11( $x0e ) ) return false;return $x0e - $x0d;}?> PMSL, can you do my homework too? Quote Link to comment https://forums.phpfreaks.com/topic/182166-34maximum-profit-problem/#findComment-961491 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.