Write a program to find 100 largest numbers out of an array of 1 billion numbers

You can keep a priority queue of the 100 biggest numbers, iterate through the 1 billion numbers. Whenever you encounter a number greater than the smallest number in the queue (the head of the queue), remove the head of the queue and add the new number to the queue. A priority queue implemented with a … Read more

max value of integer

In C, the language itself does not determine the representation of certain datatypes. It can vary from machine to machine, on embedded systems the int can be 16 bit wide, though usually it is 32 bit. The only requirement is that short int <= int <= long int by size. Also, there is a recommendation … Read more

How to perform .Max() on a property of all objects in a collection and return the object with maximum value [duplicate]

We have an extension method to do exactly this in MoreLINQ. You can look at the implementation there, but basically it’s a case of iterating through the data, remembering the maximum element we’ve seen so far and the maximum value it produced under the projection. In your case you’d do something like: var item = … Read more

MIN and MAX in C

Where are MIN and MAX defined in C, if at all? They aren’t. What is the best way to implement these, as generically and type safe as possible (compiler extensions/builtins for mainstream compilers preferred). As functions. I wouldn’t use macros like #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)), especially if you plan … Read more

How can I set max-length in an HTML5 “input type=number” element?

And you can add a max attribute that will specify the highest possible number that you may insert <input type=”number” max=”999″ /> if you add both a max and a min value you can specify the range of allowed values: <input type=”number” min=”1″ max=”999″ /> The above will still not stop a user from manually … Read more

Is there a Max function in SQL Server that takes two values like Math.Max in .NET?

If you’re using SQL Server 2008 (or above), then this is the better solution: SELECT o.OrderId, (SELECT MAX(Price) FROM (VALUES (o.NegotiatedPrice),(o.SuggestedPrice)) AS AllPrices(Price)) FROM Order o All credit and votes should go to Sven’s answer to a related question, “SQL MAX of multiple columns?” I say it’s the “best answer” because: It doesn’t require complicating … Read more

What is the maximum possible length of a query string?

RFC 2616 (Hypertext Transfer Protocol — HTTP/1.1) states there is no limit to the length of a query string (section 3.2.1). RFC 3986 (Uniform Resource Identifier — URI) also states there is no limit, but indicates the hostname is limited to 255 characters because of DNS limitations (section 2.3.3). While the specifications do not specify … Read more

Getting the index of the returned max or min item using max()/min() on a list

Say that you have a list values = [3,6,1,5], and need the index of the smallest element, i.e. index_min = 2 in this case. Avoid the solution with itemgetter() presented in the other answers, and use instead index_min = min(range(len(values)), key=values.__getitem__) because it doesn’t require to import operator nor to use enumerate, and it is … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)