[LeetCode] Range Product Queries of Powers

2438. Range Product Queries of Powers

Given a positive integer n, there exists a 0-indexed array called powers, composed of the minimum number of powers of 2 that sum to n. The array is sorted in non-decreasing order, and there is only one way to form the array.

You are also given a 0-indexed 2D integer array queries, where queries[i] = [lefti, righti]. Each queries[i] represents a query where you have to find the product of all powers[j] with lefti <= j <= righti.

Return an array answers, equal in length to queries, where answers[i] is the answer to the ith query. Since the answer to the ith query may be too large, each answers[i] should be returned modulo 109 + 7.

Read more
[LeetCode] Count Strictly Increasing Subarrays

2393. Count Strictly Increasing Subarrays

You are given an array nums consisting of positive integers.

Return the number of subarrays of nums that are in strictly increasing order.

A subarray is a contiguous part of an array.

Read more
[LeetCode] Design SQL

2408. Design SQL

You are given n tables represented with two arrays names and columns, where names[i] is the name of the ith table and columns[i] is the number of columns of the ith table.

You should be able to perform the following operations:

  • Insert 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.
  • Delete a row from a specific table. Note that deleting a row does not affect the id of the next inserted row.
  • Select a specific cell from any table and return its value.

Implement the SQL class:

  • SQL(String[] names, int[] columns) Creates the n tables.
  • void insertRow(String name, String[] row) Adds a row to the table namerow is equal to the number of columns in the table.
  • void deleteRow(String name, int rowId) Removes the row rowId from the table name
  • String selectCell(String name, int rowId, int columnId) Returns the value of the cell in the row rowId and the column columnId from the table name.
Read more
[LeetCode] Closest Fair Integer

2417. Closest Fair Integer

You are given a positive integer n.

We call an integer k fair if the number of even digits in k is equal to the number of odd digits in it.

Return the smallest fair integer that is greater than or equal to n.

Read more
[LeetCode] Minimum Split Into Subarrays With GCD Greater Than One

2436. Minimum Split Into Subarrays With GCD Greater Than One

You are given an array nums consisting of positive integers.

Split the array into one or more disjoint subarrays such that:

  • Each element of the array belongs to exactly one subarray, and
  • The GCD of the elements of each subarray is strictly greater than 1.

Return the minimum number of subarrays that can be obtained after the split.

Note that:

  • The GCD of a subarray is the largest positive integer that evenly divides all the elements of the subarray.
  • A subarray is a contiguous part of the array.
Read more
[AtCoder] C - 天下一二三パズルRead more
[AtCoder] C - 無駄なものが嫌いな人Read more
[AtCoder] D - マーブルRead more
[AtCoder] C - 席替えRead more
[AtCoder] D - トランプ挿入ソートRead more