- generate a new key and place it in a keystore:
- verify the content of a keystore:
- export the public key:
- delete a key:
- add a private key:
- add a public key:
As output we want the start and end indexes as well as the total sum for the biggest portion identified. There may be multiple solutions.
The O(N) idea is to walk the array while keeping track of the local best and global best. The local best is the sum of elements until the one being currently considered; we initialize both to the first element of the array and remember to begin the loop from the element in position 1!
At each time, the local best can either be improved by adding to it the current element, or reset to start from the current element otherwise. We make this consideration first and in case, move the start index of the current best solution to the current position, then we compare it against the global maximum updating it if needed.
We track the result in an auxiliary structure, Range. You can check its implementation on my Gist alongside the implementation of getLargestSumSubarray and some test cases in LargestSumSubarrayJTests.
Turns out this algorithm is called Kadane's algorithm.
//iterative inorder visit, use a stack as helper structure
private static List<Integer> doInorderVisitIterative(BST root, List<Integer> out){
if(root == null) return out;
BST curr = root;
Stack<BST> s = new Stack<>();
//keep looping as long as we have at least one valid element
while(!s.isEmpty() || curr != null){
//if current element is not null, keep stacking the left children
if(curr != null){
s.push(curr);
curr = curr.left;
}
//when we get a null, move up the tree (in stack view) again, visit the node, and switch to the right subtree
else{
curr = s.pop();
out.add(curr.getVal());
curr = curr.right;
}
}
return out;
}
while(number > 0) {
digit = number % 10;
number /= 10; //discard the digit and advance to the next spot
}
public int count(){
int tot = 0;
for(byte b = 0b00000001; b != 0b00000000; b = (byte)(b << 1)){
if((b & res) == b) tot++;
}
return tot;
}
public void set(int bit){
byte b = (byte)(1 << (bit - 1));
res |= b;
}
if(i - 1 >= 0 && !visited.get(M[i - 1][j])) //do something
if(i - 1 >= 0 && j - 1 >= 0 && !visited.get(M[i - 1][j - 1])) //do something
if(i - 1 >= 0 && j + 1 < N && !visited.get(M[i - 1][j + 1])) //do something
if(j - 1 >= 0 && !visited.get(M[i][j - 1])) //do something
if(j + 1 < N && !visited.get(M[i][j + 1])) //do something
if(i + 1 < N && j - 1 >= 0 && !visited.get(M[i + 1][j - 1])) //do something
if(i + 1 < N && !visited.get(M[i + 1][j])) //do something
if(i + 1 < N && j + 1 < N && !visited.get(M[i + 1][j + 1])) //do something
int[] di = {-1, -1, -1, 0, 0, 1, 1, 1};
int[] dj = {0, -1, 1, -1, 1, -1, 0, 1};
for(int n = 0; n < di.length; n++){
int x = i + di[n], y = j + dj[n];
if(x >= 0 && x < N && y >= 0 && y < N && !visited.get(M[x][y])) //do something
}
private int decodeCoordinate(int value, boolean is_column){
//column we can find with modulus
//last column is 0 if we do this calculation, but we are going for random spots so we don't care to correct it
if(is_column) return value % fieldLength;
//rows we can find with a normal division and then picking the ceiling of it, converting to 0-based!
double a = (double) value, b = (double) fieldLength;
int c = (int) Math.ceil(a / b);
return c - 1;
}