Why is ” > 0 True in Python 2?

The original design motivation for allowing order-comparisons of arbitrary objects was to allow sorting of heterogeneous lists — usefully, that would put all strings next to each other in alphabetical order, and all numbers next to each other in numerical order, although which of the two blocks came first was not guaranteed by the language. … Read more

Median of 5 sorted arrays

(This is a generalization of your idea for two arrays.) If you start by looking at the five medians of the five arrays, obviously the overall median must be between the smallest and the largest of the five medians. Proof goes something like this: If a is the min of the medians, and b is … Read more

C++ interview preparation [closed]

Make sure you know your basic data structures and algorithms. You’re more likely to be asked about that stuff than something higher up the food chain. Those are usually saved for the in-person interview. Put another way: be solid with the fundamentals and solid with your C++ syntax. Also, knowledge of common libraries like STL … Read more

Fastest way of finding the middle value of a triple?

There’s an answer here using min/max and no branches (https://stackoverflow.com/a/14676309/2233603). Actually 4 min/max operations are enough to find the median, there’s no need for xor’s: median = max(min(a,b), min(max(a,b),c)); Though, it won’t give you the median value’s index… Breakdown of all cases: a b c 1 2 3 max(min(1,2), min(max(1,2),3)) = max(1, min(2,3)) = max(1, … Read more

Multi-variable switch statement in C#

Yes. It’s supported as of .NET 4.7 and C# 8. The syntax is nearly what you mentioned, but with some parenthesis (see tuple patterns). switch ((intVal1, strVal2, boolVal3)) { case (1, “hello”, false): break; case (2, “world”, false): break; case (2, “hello”, false): break; } If you want to switch and return a value there’s … Read more

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