Given a finite non-degenerate set-theoretic solution (X, r) of the Yang-Baxter equation and a field K, the structure K-algebra of (X, r) is A = A(K, X, r) = K X | xy = uv whenever r(x, y) = (u, v) . Note that A = ⊕ n≥0 An is a graded algebra, where An is the linear span of all the elements x1 · · · xn, for x1, . . . , xn ∈ X. One of the known results asserts that the maximal possible value of dim(A2) corresponds to involutive solutions and implies several deep and important properties of A(K, X, r). Following recent ideas of Gateva-Ivanova [21], we focus on the minimal possible values of the dimension of A2. We determine lower bounds and completely classify solutions (X, r) for which these bounds are attained in the general case and also in the squarefree case. This is done in terms of the so called derived solution, introduced by Soloviev and closely related with racks and quandles. Several problems posed in [21] are solved.