You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<li><strong>Surround</strong>: The region is surrounded with <code>'X'</code> cells if you can <strong>connect the region </strong>with <code>'X'</code> cells and none of the region cells are on the edge of the <code>board</code>.</li>
81445
81445
</ul>
81446
81446
81447
-
<p>A <strong>surrounded region is captured</strong> by replacing all <code>'O'</code>s with <code>'X'</code>s in the input matrix <code>board</code>.</p>
81447
+
<p>To capture a <strong>surrounded region</strong>, replace all <code>'O'</code>s with <code>'X'</code>s <strong>in-place</strong> within the original board. You do not need to return anything.</p>
<p>You are given <code>n</code> tables represented with two arrays <code>names</code> and <code>columns</code>, where <code>names[i]</code> is the name of the <code>i<sup>th</sup></code> table and <code>columns[i]</code> is the number of columns of the <code>i<sup>th</sup></code> table.</p>
81424
+
<p>You are given two string arrays, <code>names</code> and <code>columns</code>, both of size <code>n</code>. The <code>i<sup>th</sup></code> table is represented by the name <code>names[i]</code> and contains <code>columns[i]</code> number of columns.</p>
81425
81425
81426
-
<p>You should be able to perform the following <strong>operations</strong>:</p>
81426
+
<p>You need to implement a class that supports the following <strong>operations</strong>:</p>
81427
81427
81428
81428
<ul>
81429
-
<li><strong>Insert</strong> a row in a specific table. Each row you insert has an id. The id is assigned using an auto-increment method where the id of the first inserted row is 1, and the id of each other row inserted into the same table is the id of the last inserted row (even if it was deleted) plus one.</li>
81430
-
<li><strong>Delete</strong> a row from a specific table. <strong>Note</strong> that deleting a row does not affect the id of the next inserted row.</li>
81429
+
<li><strong>Insert</strong> a row in a specific table with an idassigned using an <em>auto-increment</em> method, where the id of the first inserted row is 1, and the id of each <em>new </em>row inserted into the same table is <strong>one greater</strong> than the id of the <strong>last inserted</strong> row, even if the last row was <em>removed</em>.</li>
81430
+
<li><strong>Remove</strong> a row from a specific table. Removing a row <strong>does not</strong> affect the id of the next inserted row.</li>
81431
81431
<li><strong>Select</strong> a specific cell from any table and return its value.</li>
81432
+
<li><strong>Export</strong> all rows from any table in csv format.</li>
81432
81433
</ul>
81433
81434
81434
81435
<p>Implement the <code>SQL</code> class:</p>
81435
81436
81436
81437
<ul>
81437
-
<li><code>SQL(String[] names, int[] columns)</code> Creates the <code>n</code> tables.</li>
81438
-
<li><code>void insertRow(String name, String[] row)</code> Adds a row to the table <code>name</code>. It is <strong>guaranteed</strong> that the table will exist, and the size of the array <code>row</code> is equal to the number of columns in the table.</li>
81439
-
<li><code>void deleteRow(String name, int rowId)</code> Removes the row <code>rowId</code> from the table <code>name</code>. It is <strong>guaranteed</strong> that the table and row will <strong>exist</strong>.</li>
81440
-
<li><code>String selectCell(String name, int rowId, int columnId)</code> Returns the value of the cell in the row <code>rowId</code> and the column <code>columnId</code> from the table <code>name</code>.</li>
<li>Inserts <code>row</code> into the table <code>name</code> and returns <code>true</code>.</li>
81447
+
<li>If <code>row.length</code> <strong>does not</strong> match the expected number of columns, or <code>name</code> is <strong>not</strong> a valid table, returns <code>false</code> without any insertion.</li>
81448
+
</ul>
81449
+
</li>
81450
+
<li><code>void rmv(String name, int rowId)</code>
81451
+
<ul>
81452
+
<li>Removes the row <code>rowId</code> from the table <code>name</code>.</li>
81453
+
<li>If <code>name</code> is <strong>not</strong> a valid table or there is no row with id <code>rowId</code>, no removal is performed.</li>
81454
+
</ul>
81455
+
</li>
81456
+
<li><code>String sel(String name, int rowId, int columnId)</code>
81457
+
<ul>
81458
+
<li>Returns the value of the cell at the specified <code>rowId</code> and <code>columnId</code> in the table <code>name</code>.</li>
81459
+
<li>If <code>name</code> is <strong>not</strong> a valid table, or the cell <code>(rowId, columnId)</code> is <strong>invalid</strong>, returns <code>"<null>"</code>.</li>
81460
+
</ul>
81461
+
</li>
81462
+
<li><code>String[] exp(String name)</code>
81463
+
<ul>
81464
+
<li>Returns the rows present in the table <code>name</code>.</li>
81465
+
<li>If name is <strong>not</strong> a valid table, returns an empty array. Each row is represented as a string, with each cell value (<strong>including</strong> the row's id) separated by a <code>","</code>.</li>
SQL sql = new SQL(["one", "two", "three"], [2, 3, 1]); // creates three tables.
81455
-
sql.insertRow("two", ["first", "second", "third"]); // adds a row to the table "two". Its id is 1.
81456
-
sql.selectCell("two", 1, 3); // return "third", finds the value of the third column in the row with id 1 of the table "two".
81457
-
sql.insertRow("two", ["fourth", "fifth", "sixth"]); // adds another row to the table "two". Its id is 2.
81458
-
sql.deleteRow("two", 1); // deletes the first row of the table "two". Note that the second row will still have the id 2.
81459
-
sql.selectCell("two", 2, 2); // return "fifth", finds the value of the second column in the row with id 2 of the table "two".
<li><code>names[i]</code>, <code>row[i]</code>, and <code>name</code> consist only of lowercase English letters.</li>
81573
+
<li><code>1 <= columns[i] <= 10</code></li>
81574
+
<li><code>1 <= row.length <= 10</code></li>
81575
+
<li>All <code>names[i]</code> are <strong>distinct</strong>.</li>
81576
+
<li>At most <code>2000</code> calls will be made to <code>ins</code> and <code>rmv</code>.</li>
81577
+
<li>At most <code>10<sup>4</sup></code> calls will be made to <code>sel</code>.</li>
81578
+
<li>At most <code>500</code> calls will be made to <code>exp</code>.</li>
81477
81579
</ul>
81478
81580
81581
+
<p> </p>
81582
+
<p><strong>Follow-up:</strong> Which approach would you choose if the table might become sparse due to many deletions, and why? Consider the impact on memory usage and performance.</p>
0 commit comments