• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Write Algorithm – interview question"

Collapse

  • ratewhore
    replied
    shoulda just said 'send it to India'. Or would that make you a PM?

    Leave a comment:


  • Jabberwocky
    replied
    Originally posted by PerlOfWisdom
    So which part of the BT NHS project are you working??? on?
    That reminds me ...

    8) we need a team of testers
    9) an IT support group
    10) A budget for a couple of nights out to build team moral
    11) A guy to keep the newspapers in the bogs freshly stocked - AtW, are you free ?

    Leave a comment:


  • PerlOfWisdom
    replied
    Originally posted by Jabberwocky
    Well here is the JabberContractor solution:

    0) get the hardware, we need plenty of servers to cope with demand, two for the db, one for the application server, two for web servers (redundancy), a further db server for the data analysts to enter the times. Then we need two further boxes for development work.
    1) We need a database to store the times, so buy and install Oracle
    2) We shall use Java, so install the Java run time on all boxes.
    3) Obviously there will be a fourth generation user interface, so install Apache and a content management system to store user pages + graphics.
    4) Tomcat provides the servlet server to handle dynamic interaction.
    5) Now we will use distributed objects to distribute the load, so install an application server with an EJB container.
    6) Next we hire a team of Java contractors, a PM to manage them and a team of data analysts to enter the data.
    7) We download the code off the internet, sit back and read a user manual for three months.
    So which part of the BT NHS project are you working??? on?

    Leave a comment:


  • Jabberwocky
    replied
    Well here is the JabberContractor solution:

    0) get the hardware, we need plenty of servers to cope with demand, two for the db, one for the application server, two for web servers (redundancy), a further db server for the data analysts to enter the times. Then we need two further boxes for development work.
    1) We need a database to store the times, so buy and install Oracle
    2) We shall use Java, so install the Java run time on all boxes.
    3) Obviously there will be a fourth generation user interface, so install Apache and a content management system to store user pages + graphics.
    4) Tomcat provides the servlet server to handle dynamic interaction.
    5) Now we will use distributed objects to distribute the load, so install an application server with an EJB container.
    6) Next we hire a team of Java contractors, a PM to manage them and a team of data analysts to enter the data.
    7) We download the code off the internet, sit back and read a user manual for three months.

    Leave a comment:


  • tim123
    replied
    I got caught by an interview question like this once.

    I thought that he wanted to see how neat an algorithm I could come up with.

    He didn't, he was more interested in seeing whether I bothered to validate the parameters etc before using them, which of course I had taken as read in an interview question but would have done in the real world.

    I was annoyed with being caught out (not that I actually wanted the job).

    tim

    Leave a comment:


  • Rebecca Loos
    replied
    Also it depends what programming language we are talking about
    In Oracle PL/SQL you can use the decode function and write it in a one liner with it

    Leave a comment:


  • BlasterBates
    replied
    Its beyond me why anyone would write a recursive algorithm especially
    when you can write this as a one liner.

    Leave a comment:


  • Bovvered
    replied
    Originally posted by RSoles
    One golden rule of recursion:-

    "Never use recursion"

    Computers' resources are finite, recursion's appetite for resources isn't.
    Shut up.


    P.S. I'm not promoting recursion for the algorithm in discussion.
    P.P.S. Developers who write off techniques in one sweeping comment are generally crap.

    Leave a comment:


  • Sysman
    replied
    Anyone notice the question has an error?

    ... perhaps that was the real point of the exercise.

    Just my banking experience showing through :-)

    Leave a comment:


  • messiah
    replied
    also there was no mention of needing current time in the parameters only a start and end time.

    or am I wrong .... should I wear the dunces cap ?

    Leave a comment:


  • Jabberwocky
    replied
    Originally posted by AtW
    Christ, is it what they pay stupid money for working in Banks?

    -------------------------------------------------------
    8:01 - 9:00 20% [i.e each minute is 1/3 %]
    9:01 - 10:00 40% [i.e each minute is 2/3 %]
    10:01 - 11:00 30% [i.e each minute is 1/2 %]
    11:01 - 12:00 10% [i.e each minute is 1/6 %]
    -------------------------------------------------------

    1) you need simple function - CalcTradingRatio that accepts the following arguements:

    a) %-tage of trading in given period
    b) period start time, ie 8:01
    c) period end time, ie 9:00
    d) current time: this can be
    d1) INSIDE period - in this case you calculation and return fraction of parameter a)
    d2) BEFORE period starts (ie smaller then b) - return 0
    d3) AFTER period ends - return full value a)

    2) macro function that calls 1) for all periods:

    string sCurTime="8:55";
    int iTradingDone=0;

    iTradingDone+=CalcTradingRatio("20","8:01","9:00", sCurTime);
    iTradingDone+=CalcTradingRatio("40","9:01","10:00" ,sCurTime);
    iTradingDone+=CalcTradingRatio("30","10:01","11:00 ",sCurTime);
    iTradingDone+=CalcTradingRatio("10","11:01","12:00 ",sCurTime);
    I wouldn't hire you mr atw - pass your parameters in using the correct type - percentages are floats, times should be typed too - what if the caller assumes a 24 hour clock - also I don't like iTradingDone as an int - what about rounding errors on each call - gosh the things I have to teach you people on here.

    JabberNerd
    Last edited by Jabberwocky; 4 December 2005, 01:12.

    Leave a comment:


  • AtW
    replied
    Originally posted by Rebecca Loos
    AtW, I agree your solution is more elegant than mine
    I actually would not be suprised if they accepted your solution rather than mine...

    IMO there is too big emphasis onto how this simple problem is to be solved - they should be giving some real hard problems where solving the problem is important, not whether you use external function or not.

    Perhaps the real answer they were looking for was that you will just outsource coding to people on Rent-A-Coder.
    Last edited by AtW; 2 December 2005, 18:14.

    Leave a comment:


  • DimPrawn
    replied
    Can I provide a solution by dragging pretty coloured icons onto a designer surface and then have a cup of tea?

    Leave a comment:


  • Rebecca Loos
    replied
    AtW, I agree your solution is more elegant than mine

    But I wrote it in one single block on the grounds that the bank rejected a solution with an external function call

    Leave a comment:


  • Singleton
    replied
    Originally posted by AtW
    Christ, is it what they pay stupid money for working in Banks?

    -------------------------------------------------------
    8:01 - 9:00 20% [i.e each minute is 1/3 %]
    9:01 - 10:00 40% [i.e each minute is 2/3 %]
    10:01 - 11:00 30% [i.e each minute is 1/2 %]
    11:01 - 12:00 10% [i.e each minute is 1/6 %]
    -------------------------------------------------------

    1) you need simple function - CalcTradingRatio that accepts the following arguements:

    a) %-tage of trading in given period
    b) period start time, ie 8:01
    c) period end time, ie 9:00
    d) current time: this can be
    d1) INSIDE period - in this case you calculation and return fraction of parameter a)
    d2) BEFORE period starts (ie smaller then b) - return 0
    d3) AFTER period ends - return full value a)

    2) macro function that calls 1) for all periods:

    string sCurTime="8:55";
    int iTradingDone=0;

    iTradingDone+=CalcTradingRatio("20","8:01","9:00", sCurTime);
    iTradingDone+=CalcTradingRatio("40","9:01","10:00" ,sCurTime);
    iTradingDone+=CalcTradingRatio("30","10:01","11:00 ",sCurTime);
    iTradingDone+=CalcTradingRatio("10","11:01","12:00 ",sCurTime);

    --

    There done - pretty simple.

    A faster way however is to split all periods into minutes and calculate cumulative trading done up to any given minute - put it all into array, then in order to calculate trading done in any given time you just calculate number of minutes from 8:00am and just look up trading value in array - this is very fast as pre-computation is needed only once.

    Can't see ANY need for recursion here.
    Sorry, I didn't get that one .. lets say start time is 8:15 and end time is 10:50 tell me how your solution works?

    Leave a comment:

Working...
X