April 28, 2022

Making entire row and column of matrix to zero if one element is zero | alternative approach


Given a matrix if an element in the matrix is 0 then you will have to set its entire column and row to 0 and then return the matrix.
 



/**
 * Given a matrix if an element in the matrix is 0 then you will have to set its entire column and row to 0 and then return the matrix.
 */
package com.striver.sde.practice;

import java.util.ArrayList;
import java.util.List;

/**
 * @author apple
 *
 */
public class MatrixZero {

/**
* @param args
*/
public static void main(String[] args) {

int[][] input = { { 1, 1, 1 }, { 1, 0, 1 }, { 1, 1, 1 } };

MatrixZero m = new MatrixZero();
// m.findSolution(input);
m.findSolution2(input);

}

private void findSolution2(int[][] input) {
int len = input.length;

List rows = new ArrayList<>();
List cols = new ArrayList<>();

for (int row = 0; row < len; row++) {

for (int col = 0; col < len; col++) {

if (input[row][col] == 0) {
rows.add(row);
cols.add(col);
}

}

}
for (int row = 0; row < len; row++) {

for (int col = 0; col < len; col++) {

if(rows.contains(row)) {
input[row][col] =0;
}
if(cols.contains(col)) {
input[row][col] =0;
}

}

}
System.out.println(input);
}

private void findSolution(int[][] input) {

int[][] output = input.clone();

int len = input.length;

for (int row = 0; row < len; row++) {

for (int col = 0; col < len; col++) {

if (input[row][col] == 0) {

modifyMatrix(row, col, output, len);

}

}

}

}

private void modifyMatrix(int row, int col, int[][] output, int len) {

if (row == 0) {
int r = row;
while (r < len) {
output[r][col] = 0;
r = r + 1;
}

} else if (row == len) {
int r = row;
while (r >= 0) {
output[r][col] = 0;
r = r - 1;
}

} else {

}

}

}

April 21, 2022

Stock market trading | morning star candle stick pattern explained | How to set up an entry point | best to buy




Sample graph : Morning star candle stick pattern explained

we have taken last 3 month stock trading of SBI, in the yellow color we marked morning start candle stick pattern.

What is morning star candle stick pattern ?


Its a 3 candle stick pattern (Multiple candle stick pattern) which denotes 3 successive days.

for example apr 21 2022, apr 22 2022, apr 23 2022 in each candle.

Its a trend reversal pattern.


How and where to check morning star candle stick pattern?


Check whether the morning star candle stick pattern is formed after a downtrend.

In morning star candle pattern

1. The first candle will a bearish one

2. The second candle will be either a doji or spinning top, here the color may be green or red

if its green then its a good indicator to buy

The second candle should be a gap down opening, ie the opening value should be lesser than first candle closing value.

3. The third one must be a bulish candle and opening should be gap up opening.


What morning star candle stick says?


Its a entry point for short term or long term.











Facebook comments