Hi everyone, there is one interesting task from the last interview. I am sure that such a task has already been encountered at one of the past contests on leetcode. I'd appreciate if anyone could help solve this problem or share a solution.
I suppose that the task will be clear from the input and output data.
Input format:
-number of rows and columns specifying the ASCII description of the table;
-ASCII table description;
-number of table rows;
-table row heights;
-number of table columns;
-table column widths;
-number of queries;
-queries;
Query format:
merge "cell1" "cell2" (cells can only be merged if they are aligned vertically or horizontally);
split "cell1" (need to split a cell into unit cells, a cell can be splited only if it is not unit (elementary) cell);
Cells naming:
columns: A,B,C,…,Z,AA,AB,AC,…,AZ,BA,…,AAA,AAB,...
rows: 1, 2, 3, ...
Input:
5 11
+--+------+
| | |
+--+----+-+
| | |
+-------+-+
2
1 1
3
2 4 1
6
merge B1 A2
merge A2 C2
merge A2 B2
split A1
split C2
merge A1 A2Output:
Can not merge unaligned cells
Merged horizontally-aligned cells
+--+------+
| | |
+--+------+
| |
+---------+
Can not merge cell with itself
Can not split elementary cell
Split onto 3 cells
+--+------+
| | |
+--+----+-+
| | | |
+--+----+-+
Merged vertically-aligned cells
+--+------+
| | |
| +----+-+
| | | |
+--+----+-+I'd be appreciate for any ideas. Thanks.