## Check Sudoku

Solutions We need to check if any row, columns or sub-grid contains duplicates. We can use an array of booleans (or a frequency array) for each type of component to check. Here is the idea: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 int main() { bool row{}, column{}, grid{}; int N, r, c, v; cin >> N; for (int i = 0; i < N; ++i) { cin >> r >> c >> v; r--; c--; v--; if (row[r][v] || column[c][v] || grid[r / 3][c / 3][v]) { cout << "WRONG INPUT"; return 0; } row[r][v] = column[c][v] = grid[r / 3][c / 3][v] = true; } cout << "OK"; } Basically, we read a coordinate and we check if it has been already allocated in any of the component. [Read More]

## Day of the Programmer

Solutions This problem seems convoluted but it can be solved very easily if decomposed in terms of simple predicates: if the year is 1918, we can directly return the day 26.09.1918 otherwise we can check if the year is leap. In this case we return 12.09 and the year if the year is not leap, we just return 13.09 and the year To determine if a year is leap, we have to apply either the Julian - if the year is less than 1918 - or the Gregorian rule - otherwise. [Read More]

## Distracted Shopkeeper

Shopkeepers often round up the change during a purchase so that the change to be given can be a single bill, making it convenient for both the shopkeeper and the customer. For example, a customer has paid a $$200$$ sesterzio bill for a purchase of $$104$$ sesterzi. If the customer then gives an additional $$4$$ sesterzi, then the cashier will give an exact $$100$$ sesterzio bill in change, instead of several bills and coins if the change is $$96$$ sesterzi. [Read More]

## Evaluate Expression

You are given an expression in Reverse Polish Notation (RPN) and you have to evaluate it. Input Format Space separated terms of the expression to evaluate (at least one element). Constraints Each numeric element fits an int32. Any other token is either +, -, *, / The result is guaranteed not to go beyond the int32 representation Output Format The result of the expression evaluation, as a single number. Solutions The solution for this excercise would be to use a stack. [Read More]

Solutions This problem can be solved in several ways, each carrying its own pros, cons and tradeoffs. All the solutions are based on this observation: the answer is always $$max(6-n,4-d)$$ where $$n$$ is string length and $$d$$ is the number of different type of characters that are already present in the input password. Preamble We call character family the group of characters belonging to the same requirement. The problem requires to check against 4: digits, lowercase letters, uppercase letters, special chars. [Read More]