Search Results

Search found 7086 results on 284 pages for 'explain'.

Page 6/284 | < Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >

  • Explain the Peak and Flag Algorithm

    - by Isaac Levin
    EDIT Just was pointed that the requirements state peaks cannot be ends of Arrays. So I ran across this site http://codility.com/ Which gives you programming problems and gives you certificates if you can solve them in 2 hours. The very first question is one I have seen before, typically called the Peaks and Flags question. If you are not familiar A non-empty zero-indexed array A consisting of N integers is given. A peak is an array element which is larger than its neighbours. More precisely, it is an index P such that 0 < P < N - 1 and A[P - 1] < A[P] A[P + 1] . For example, the following array A: A[0] = 1 A[1] = 5 A[2] = 3 A[3] = 4 A[4] = 3 A[5] = 4 A[6] = 1 A[7] = 2 A[8] = 3 A[9] = 4 A[10] = 6 A[11] = 2 has exactly four peaks: elements 1, 3, 5 and 10. You are going on a trip to a range of mountains whose relative heights are represented by array A. You have to choose how many flags you should take with you. The goal is to set the maximum number of flags on the peaks, according to certain rules. Flags can only be set on peaks. What's more, if you take K flags, then the distance between any two flags should be greater than or equal to K. The distance between indices P and Q is the absolute value |P - Q|. For example, given the mountain range represented by array A, above, with N = 12, if you take: two flags, you can set them on peaks 1 and 5; three flags, you can set them on peaks 1, 5 and 10; four flags, you can set only three flags, on peaks 1, 5 and 10. You can therefore set a maximum of three flags in this case. Write a function that, given a non-empty zero-indexed array A of N integers, returns the maximum number of flags that can be set on the peaks of the array. For example, given the array above the function should return 3, as explained above. Assume that: N is an integer within the range [1..100,000]; each element of array A is an integer within the range [0..1,000,000,000]. Complexity: expected worst-case time complexity is O(N); expected worst-case space complexity is O(N), beyond input storage (not counting the storage required for input arguments). Elements of input arrays can be modified. So this makes sense, but I failed it using this code public int GetFlags(int[] A) { List<int> peakList = new List<int>(); for (int i = 0; i <= A.Length - 1; i++) { if ((A[i] > A[i + 1] && A[i] > A[i - 1])) { peakList.Add(i); } } List<int> flagList = new List<int>(); int distance = peakList.Count; flagList.Add(peakList[0]); for (int i = 1, j = 0, max = peakList.Count; i < max; i++) { if (Math.Abs(Convert.ToDecimal(peakList[j]) - Convert.ToDecimal(peakList[i])) >= distance) { flagList.Add(peakList[i]); j = i; } } return flagList.Count; } EDIT int[] A = new int[] { 7, 10, 4, 5, 7, 4, 6, 1, 4, 3, 3, 7 }; The correct answer is 3, but my application says 2 This I do not get, since there are 4 peaks (indices 1,4,6,8) and from that, you should be able to place a flag at 2 of the peaks (1 and 6) Am I missing something here? Obviously my assumption is that the beginning or end of an Array can be a peak, is this not the case? If this needs to go in Stack Exchange Programmers, I will move it, but thought dialog here would be helpful. EDIT

    Read the article

  • Can someone explain me implicit conversions in Scala?

    - by Oscar Reyes
    And more specifically how does the BigInt works for convert int to BigInt? In the source code it reads: ... implicit def int2bigInt(i: Int): BigInt = apply(i) ... How is this code invoked? I can understand how this other sample: "Date literals" works. In. val christmas = 24 Dec 2010 Defined by: implicit def dateLiterals(date: Int) = new { import java.util.Date def Dec(year: Int) = new Date(year, 11, date) } When int get's passed the message Dec with an int as parameter, the system looks for another method that can handle the request, in this case Dec(year:Int) Q1. Am I right in my understanding of Date literals? Q2. How does it apply to BigInt? Thanks

    Read the article

  • Please explain this python behavior

    - by StackUnderflow
    class SomeClass(object): def __init__(self, key_text_pairs = None): ..... for key, text in key_text_pairs: ...... ...... x = SomeClass([1, 2, 3]) The value of key_text_pairs inside the init is None even if I pass a list as in the above statement. Why is it so?? I want to write a generic init which can take all iterator objects... Thanks

    Read the article

  • Explain this AS2 code?

    - by incrediman
    Why does this code trace 'undefined'? this.createEmptyMovieClip("myLoader",1); trace(this.myLoader); this too? this.createEmptyMovieClip("myLoader",1); trace(this["myLoader"]); (when the code is in the constructor of a class which extends MovieClip) But this code traces _level0.myLoader (code placed on main timeline) this.createEmptyMovieClip("myLoader",1); trace(this.myLoader);

    Read the article

  • Can someone explain me the parameter RETURN_VALUE ?

    - by Ronnie Chester Lynwood
    hello. I want to know what does RETURN_VALUE means! I'm stucked at this thing. how to use RETURN_VALUE on MSSQL SP ? thanks.. ASP: Set cmdDB = Server.CreateObject("ADODB.Command") With cmdDB .ActiveConnection = ADOConM .CommandText = "usp_jaljava_member_select" .CommandType = adCmdStoredProc .Parameters.Append .CreateParameter("RETURN_VALUE", adInteger, adParamReturnValue, 0) .Parameters.Append .CreateParameter("@TLoginName", adVarChar, adParamInput, 15,lcase(TLoginName)) .Parameters.Append .CreateParameter("@TPassword", adVarChar, adParamInput, 20,TPassword) .Parameters.Append .CreateParameter("@retval", adVarChar, adParamOutput, 50) ' .Parameters.Append .CreateParameter("@TPinCode", adVarChar, adParamInput, 15,TPinCode) .Execute,,adExecuteNoRecords RetVal = .Parameters("@retval") Ret = Trim(.Parameters("RETURN_VALUE")) 'Set .ActiveConnection = Nothing End With Set cmdDB = Nothing UTid = RetVal MSSQL SP: CREATE PROCEDURE usp_jaljava_member_select @TLoginName varchar(15), @TPassword varchar(20), @retval varchar(50) OUTPUT --@TPinCode varchar(15) AS

    Read the article

  • Query column and everything subordinate (hard to describe, non native speaker, PLS let me explain)

    - by MAD9
    A few weeks ago, I asked a question about how to generate hierarchical XML from a table, that has a parentID column. It all works fine. The point is, according to the hierarchy, I also want to query a table. I'll give you an example: Thats the table with the codes: ID CODE NAME PARENTID 1 ROOT IndustryCode NULL 2 IND Industry 1 3 CON Consulting 1 4 FIN Finance 1 5 PHARM Pharmaceuticals 2 6 AUTO Automotive 2 7 STRAT Strategy 3 8 IMPL Implementation 3 9 CFIN Corporate Finance 4 10 CMRKT Capital Markets 9 From which I generate (for displaying in a TreeViewControl) this XML: <record key="1" parentkey="" Code="ROOT" Name="IndustryCode"> <record key="2" parentkey="1" Code="IND" Name="Industry"> <record key="5" parentkey="2" Code="PHARM" Name="Pharmaceuticals" /> <record key="6" parentkey="2" Code="AUTO" Name="Automotive" /> </record> <record key="3" parentkey="1" Code="CON" Name="Consulting"> <record key="7" parentkey="3" Code="STRAT" Name="Strategy" /> <record key="8" parentkey="3" Code="IMPL" Name="Implementation" /> </record> <record key="4" parentkey="1" Code="FIN" Name="Finance"> <record key="9" parentkey="4" Code="CFIN" Name="Corporate Finance"> <record key="10" parentkey="9" Code="CMRKT" Name="Capital Markets" /> </record> </record> </record> As you can see, some codes are subordinate to others, for example AUTO << IND << ROOT What I want (and have absolutely no idea how to realise or even, where to start) is to be able to query another table (where one column is this certain code of course) for a code and get all records with the specific code and all subordinate codes For example: I query the other table for "IndustryCode = IND[ustry]" and get (of course) the records containing "IND", but also AUTO[motive] and PHARM[aceutical] (= all subordinates) Its an SQL Express Server 2008 with Advanced Services.

    Read the article

  • Could someone please explain this REGEX?

    - by NJTechGuy
    if($title =~ s/(\s|^|,|\/|;|\|)$replace(\s|$|,|\/|;|\|)//ig) $title can be a set of titles ranging from President, MD, COO, CEO,... $replace can be (shareholder), (Owner) or the like. I keep getting this error. I have checked for improperly balanced '(', ')', no dice :( Unmatched ) in regex; marked by <-- HERE in m/(\s|^|,|/|;|\|)Owner) <-- HERE (\s|$|,|/|;|\|)/ If you could tell me what the regex does, that had be awesome. It strips those symbols is it? Sorry long day at work. Thanks guys!

    Read the article

  • Question about Cost in Oracle Explain Plan

    - by Will
    When Oracle is estimating the 'Cost' for certain queries, does it actually look at the amount of data (rows) in a table? For example: If I'm doing a full table scan of employees for name='Bob', does it estimate the cost by counting the amount of existing rows, or is it always a set cost?

    Read the article

  • Explain why MickroC pic18f4550 HID example works

    - by Dr Deo
    MickroC compiler has a library for HID(Human Interface Device) usb communication. In the supplied samples, they specify that the buffers below should be in USB ram and use a pic18f4550. unsigned char readbuff[64] absolute 0x500; // Buffers should be in USB RAM, please consult datasheet unsigned char writebuff[64] absolute 0x540; But the pic18f4550 datasheet says USB ram ranges from 400h to 4FFh So why does their example work when their buffers appear not to be between 400h to 4FFh? Link to full source

    Read the article

  • Please Explain .NET Delegates

    - by user275561
    So I read MSDN and Stack Overflow. I understand what the Action Delegate does in general but it is not clicking no matter how many examples I do. In general, the same goes for the idea of delegates. So here is my question. When you have a function like this: public GetCustomers(Action<IEnumerable<Customer>,Exception> callBack) { } What is this, and what should I pass to it?

    Read the article

  • Delphi> Please explain this: type... procedure of object

    - by Richard Woolf
    I've encountered some code that's new to me... I've never really seen a type declaration of a procedure of object, and I just don't see the point. Why couldn't the developer simply keep a field of type Boolean? interface type TFinishedCaptureEvent = procedure(AFinished: Boolean) of object; TFrameCard = class(TFrame) ... private FOnFinishedCapture: TFinishedCaptureEvent; public property OnFinishedCapture: TFinishedCaptureEvent read FOnFinishedCapture write FOnFinishedCapture; end; implementation ... if Assigned(FOnFinishedCapture) then FOnFinishedCapture(False);

    Read the article

  • Explain ML type inference to a C++ programmer

    - by Tsubasa Gomamoto
    How does ML perform the type inference in the following function definition: let add a b = a + b Is it like C++ templates where no type-checking is performed until the point of template instantiation after which if the type supports the necessary operations, the function works or else a compilation error is thrown ? i.e. for example, the following function template template <typename NumType> NumType add(NumType a, NumType b) { return a + b; } will work for add<int>(23, 11); but won't work for add<ostream>(cout, fout); Is what I am guessing is correct or ML type inference works differently? PS: Sorry for my poor English; it's not my native language.

    Read the article

  • What arguments to use to explain why SQL Server is far better then a flat file

    - by jamone
    The higher ups in my company were told by good friends that flat files are the way to go, and we should switch from SQL Server to them for everything we do. We have over 300 servers and hundreds of different databases. From just the few I'm involved with we have 10 billion records in quite a few of them with upwards of 100k new records a day and who knows how many updates... Me and a couple others need to come up with a response saying why we shouldn't do this. Most of our stuff is ASP.NET with some legacy ASP. We thought that making a simple console app that tests/times the same interactions between a flat file (stored on the network) and SQL over the network doing large inserts, searches, updates etc along with things like network disconnects randomly. This would show them how bad flat files can be especially when you are dealing with millions of records. What things should I use in my response? What should I do with my demo code to illustrate this? My sort list so far: Security Concurrent access Performance with large amounts of data Amount of time to do such a massive rewrite/switch Lack of transactions PITA to map relational data to flat files NTFS doesn't support tons of files in a directory well I fear that this will be a great post on the Daily WTF someday if I can't stop it now.

    Read the article

  • Best Dijkstra papers to explain this quote?

    - by jemfinch
    I was enjoying "The Humble Programmer" earlier today and ran across this choice quote: Therefore, for the time being and perhaps forever, the rules of the second kind present themselves as elements of discipline required from the programmer. Some of the rules I have in mind are so clear that they can be taught and that there never needs to be an argument as to whether a given program violates them or not. Examples are the requirements that no loop should be written down without providing a proof for termination nor without stating the relation whose invariance will not be destroyed by the execution of the repeatable statement. I'm looking for which of Dijkstra's 1300+ writings best describe in further detail rules such as he was describing above.

    Read the article

  • Internet explorer and floats: please explain

    - by cletus
    Yesterday someone asked Width absorbing HTML elements. I presented two solutions: one table-based and one pure CSS. Now the pure CSS one works well in Firefox and Chrome but not in IE. Basically the floats are being bumped down to the next line. It is my understanding (and the behaviour of FF and Chrome) that this should not be the case because the left divs are block level elements that floats should basically ignore. Complete code example is below. Adding a DOCTYPE to force IE into standards compliant mode helps slightly but the problem remains. So my question is: am I mistaken about my understanding of floats or is this IE's problem? More importantly, how do I get this to work in IE? It's been bugging the hell out of me. <html> <head> <style type="text/css"> div div { height: 1.3em; } #wrapper { width: 300px; overflow: hidden; } div.text { float: right; white-space: nowrap; clear: both; background: white; padding-left: 12px; text-align: left; } #row1, #row2, #row3, #row4, #row5, #row6 { width: 270px; margin-bottom: 4px; } #row1 { background: red; } #row2 { background: blue; } #row3 { background: green; } #row4 { background: yellow; } #row5 { background: pink; } #row6 { background: gray; } </style> <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1.3.2"); google.setOnLoadCallback(function() { $(function() { $("div.text").animate({ width: "90%" }, 2000); }); }); </script> </head> <body> <div id="wrapper"> <div class="text">FOO</div><div id="row1"></div> <div class="text">BAR</div><div id="row2"></div> <div class="text">THESE PRETZELS ARE</div><div id="row3"></div> <div class="text">MAKING ME THIRSTY</div><div id="row4"></div> <div class="text">BLAH</div><div id="row5"></div> <div class="text">BLAH</div><div id="row6"></div> </div> </body> </html>

    Read the article

  • Explain this C++ operator definition

    - by David Johnstone
    I have the following operator defined in a C++ class called StringProxy: operator std::string&() { return m_string; } a) What is this and how does this work? I understand the idea of operator overloading, but they normally look like X operator+(double i). b) Given an instance of StringProxy, how can I use this operator to get the m_string?

    Read the article

  • Can someone explain how this works?

    - by Dan Howard
    Key in the first three digits of your phone number (NOT the Area code...) Multiply by 80 Add 1 Multiply by 250 Add to this the last 4 digits of your phone number Add to this the last 4 digits of your phone number again. Subtract 250 Divide number by 2 Do you recognize the answer??

    Read the article

  • can't explain NullPointerException

    - by John Pope
    In the following code, i have a method to get a Vector of persons with the same zodiac sign. persoane is a Vector. I keep getting a NullPointerException at the if condition (persoane is definetly not null). I am unable to see why. Any help would be greatly appreciated public Vector<Persoana> cautaDupaZodie(String zodie) { Vector<Persoana> rezultat= new Vector<Persoana>(); for(int i=0; i<persoane.size(); i++) { if(persoane.get(i).getData().getZodie().equals(zodie)) //the exception occurs here { rezultat.add(persoane.get(i)); } } return rezultat; }

    Read the article

  • explain these select statements!

    - by user329820
    Hi, I can not get the difference betwwn these statements? would you please help me,I have read some sample of select statements but I did not get these ones. SELECT 'B' FROM T WHERE A = (SELECT NULL); SELECT 'C' FROM T WHERE A = ANY (SELECT NULL); SELECT 'D' FROM T WHERE A = A; I use MySQL

    Read the article

< Previous Page | 2 3 4 5 6 7 8 9 10 11 12 13  | Next Page >