Question Definition
Java Solution
public int minSteps(int n) {
if (n == 1) return 0;
int res = n;
for (int i = n - 1; i > 1; --i) {
if (n % i == 0) {
res = Math.min(res, minSteps(n / i) + i);
}
}
return res;
}
Question Definition
Given a 2D board and a word, find if the word exists in the grid.
The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically neighboring. The same letter cell may not be used more than once.
More …
Question Definition
Given a sorted integer array without duplicates, return the summary of its ranges.
More …
Question Definition
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.
More …
Question Definition
Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.
Your algorithm’s runtime complexity must be in the order of O(log n).
If the target is not found in the array, return [-1, -1]
.
More …