List of user sessions in SQL

| category: Programming | author: st
Tags:

The frequently asked problem on interviews.

You have a log of some user activities represented as a table. Every activity record has at least users ID and activity date/time values.

The session is a sequence of activities having less than N minutes between two log records. When the elapsed …

Get all subsets from a set

| category: Programming | author: st
Tags: ,

How to extract all combinations (unordered subsets) from a given set in C++?

Let us estimate the count before. Suppose N is the size of a given set, and K is the number of elements in the subset. The count of all combinations (unordered subsets) of size K is

C …

All expressions of 123456789 and signs +/- which value is 100

| category: Programming | author: st
Tags:

Suppose a string of ordered cyphers 123456789. You can insert signs "+" and "-" between any cyphers to make a correct arithmetical expression. The problem is to find all expressions which sum is 100.

This problem may be interesting for dynamic script languages having the function of a string expression evaluation.

E …

static_cast vs dynamic_cast: undefined behavior

| category: Programming | author: st
Tags:

Do not use static_cast when you cast from a basic class to a derived one. This may lead to undefined behavior. To handle the polymorphism, a virtual inheritance or a multiple inheritance case always use dynamic_cast instead.

The following short example shows the undefined behavior cases. This works with GCC …

C++11 constructors

| category: Programming | author: st
Tags: ,

According to specification, "...constructor is a special non-static member function of a class that is used to initialize objects of its class type". In addition to basic concepts, C++11 introduces move constructors, initializer list type and brace-enclosed lists of comma-separated initializers.

However the impact of introducing new constructors combining …