whoknows
BAN USER
- 0of 0 votes
AnswerRoulette -Gamblers Fallacy. start with $50, bet opposite color every time same color 4 in a row. loop 100 time or until $0. Suggest create roulette wheel object with history, a gambler object with maybe gamblingplan object. (you can find more detailed suggestions elsewhere)
- whoknows in United States| Report Duplicate | Flag | PURGE
Google SDE1 Algorithm - 0of 0 votes
Answersthere is a 2d array and gbikes are located in that location. there is a person and he wants to know the nearest location of the bike which is available for him(there can be more than 1 nearest bike). person can only move left , right , up or down. output should be the distance in int.
- whoknows in United States| Report Duplicate | Flag | PURGE
Google
package com.algorithms.test;
public class LongestPathInMatrixWith01 {
public static int FindLongestSequences(int[][] matrix, int row,int col){
int maxCnt = 0;
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
int a = (i==0) ? 0: matrix[(i-1)][j];
int b = (j==0) ? 0: matrix[i][j-1];
System.out.println("i: "+i+" j:"+ j);
System.out.println("a: "+a+" b:"+b+" "+matrix[i][j]);
matrix[i][j] =( matrix[i][j]>0) ? max(a,b)+1 :0;
System.out.println(matrix[i][j]);
maxCnt = max(maxCnt,matrix[i][j]);
}
}
for(int i=0;i<row;i++){
for(int j=0;j<col;j++){
System.out.print(matrix[i][j]);
}
System.out.println();
}
return maxCnt;
}
public static int max(int a , int b){
return (a>b) ? a :b;
}
public static void DoTest(int[][] matrix, int rows, int col){
if(matrix == null ) return;
if(rows < 1) return;
if(col < 1) return;
for(int i=0;i<rows;i++){
for(int j=0;j<col;j++){
System.out.print(matrix[i][j]);
}
System.out.println();
}
int len = FindLongestSequences(matrix, rows, col);
System.out.println("Maximum Length "+len);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[][] matrix = {
{0, 0, 0, 1, 1},
{1, 1, 1, 0, 1},
{0, 1, 1, 1, 0},
{0, 0, 1, 0, 0},
{1, 1, 1, 1, 1}
};
DoTest(matrix,matrix.length,matrix[0].length);
}
}
@tuttobenethx
- whoknows June 10, 2018Thanks for sharing your thoughts. Can you tell me the time complexity of bleed solution
And better solution is not correct solution
if we give manPosRow = 9 and manPosCol = 3 then answer should be zero
but it is giving 4