amnesiac
BAN USER- 2of 2 votes
AnswersYou are given a board with N rows and M columns. In this board you have to place exactly 1 bishop in each row. There are also some obstacles in some of the cells where you can't place a bishop. Bishops can only move diagonally but they can't go to a cell where there is any obstacle. Two bishops can attack each other if one of them can move to the cell of the other bishop. Now you have to count the number of ways that you can place bishops in the board.
- amnesiac in United States
Note: Two bishops can attack each other if one of them can move to the cell of the other bishop in a single move without passing any obstacles.
Input Format
The first line of the input contains two integers N and M. The following N lines contain M characters each, the description of the board. Each cell of the board is either '.' which means that this cell is free or '*' which means that this cell contains an obstacle.
Constraints
1<=N,M<=10
Output Format
Print only one integer representing the number of ways to put exactly one bishop in each row such that no two bishops attack each other.
Sample Input
3 3
..*
.**
.*.
Sample Output
2| Report Duplicate | Flag | PURGE
- 1of 3 votes
AnswersN*N matrix is given with input red or black. You can move horizontally, vertically or diagonally. If 3 consecutive same color found, that color will get 1 point. So if 4 red are vertically then point is 2. Find the winner.
- amnesiac in United States| Report Duplicate | Flag | PURGE
Epic Systems Algorithm - 3of 5 votes
AnswersPrint all palindromes of size greater than equal to 3 of a given string. (DP)
- amnesiac in United States| Report Duplicate | Flag | PURGE
Epic Systems Software Engineer / Developer Algorithm - 25of 25 votes
AnswersThere is an island which is represented by square matrix NxN.
- amnesiac in India
A person on the island is standing at any given co-ordinates (x,y). He can move in any direction one step right, left, up, down on the island. If he steps outside the island, he dies.
Let island is represented as (0,0) to (N-1,N-1) (i.e NxN matrix) & person is standing at given co-ordinates (x,y). He is allowed to move n steps on the island (along the matrix). What is the probability that he is alive after he walks n steps on the island?
Write a psuedocode & then full code for function
" float probabilityofalive(int x,int y, int n) ".| Report Duplicate | Flag | PURGE
Google Software Engineer / Developer Algorithm - 0of 0 votes
AnswersSort the input character array based on the dictionary given.
- amnesiac in United States
For eg:, If input word is “SHEEP“, sorting will make it as “EEHPS“.
But in the dictionary, E may not be at first. As per the dictionary, if P is first, S followed and E later and finally H.
Then sorted array is “PSEEH“.| Report Duplicate | Flag | PURGE
Google Algorithm - 0of 0 votes
AnswersYou have 8 coins. 3 of them weigh x units, 3 y units, 1 a units and 1 b units. They are all mixed and look identical. You have to find the lightest coin in minimum number of weighing .
- amnesiac in India| Report Duplicate | Flag | PURGE
Oracle Software Engineer / Developer Brain Teasers - 0of 0 votes
AnswersThe two nodes in BST are swapped.Correct the BST.
- amnesiac in India| Report Duplicate | Flag | PURGE
Microsoft Software Engineer / Developer Coding
public class LongestPalindrome {
/**
* @param args //laxmikant's arena
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
longestPalindrome("ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD");
}
public static void longestPalindrome(String str){
int len=str.length();
int[][] table=new int[len][len];
for(int i=0;i<len;i++)
{
for(int j=0;j<len;j++)
{
table[i][j]=0;
}
}
for(int i=0;i<len-1;i++)
{
table[i][i]=1;
if(str.charAt(i)==str.charAt(i+1))
table[i][i+1]=1;
}
table[len-1][len-1]=1;
int start=0,max_len=0;
for(int k=3;k<=len;k++)
{
for (int i=0;i<=len-k;i++)
{
int j=i+k-1;
if(table[i+1][j-1]==1 && str.charAt(i)==str.charAt(j))
{
table[i][j]=1;
if(k>max_len)
{
max_len=k;
start=i;
}
}
}
}
System.out.println(str.substring(start,start+max_len));
}
}
public class palindromeStrings {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String temp="abbppqqwoooopxyz";
int[] table=new int[26];
String alpha="abcdefghijklmnopqrstuvwxyz";
for(int i=0;i<temp.length();i++)
{
table[(temp.charAt(i)-'a')]+=1;
}
pal("",table,alpha,0);
}
public static void pal(String str,int[] table,String alpha, int n)
{
if(str.length()==0)
{
//System.out.println("yo");
for(int i=0;i<table.length;i++)
{
//System.out.println("yo");
if(table[i]==1)
{
table[i]-=1;
pal(str+alpha.charAt(i),table,alpha,n+1);
}
else if(table[i]>=2)
{
table[i]=table[i]-2;
pal(alpha.charAt(i)+str+alpha.charAt(i),table,alpha,n+2);
table[i]=table[i]+2;
table[i]=table[i]-1;
pal(str+alpha.charAt(i),table,alpha,n+1);
}
else
continue;
}
}
for(int i=0;i<table.length;i++)
{
if(table[i]>=2)
{
table[i]=table[i]-2;
String temp=""+alpha.charAt(i)+str+alpha.charAt(i);
if(n+2>=3)
System.out.println(temp);
pal(alpha.charAt(i)+str+alpha.charAt(i),table,alpha,n+2);
}
}
}
}
- amnesiac February 15, 2014ya...
1. store the count of each character in array
2. for each character in an array,
iterate through array & append to output
if str.length==0
then get one char & decremnt count for that particular char
else
if count for that char is >=2
then (char+str+char) thhis will be the string for palindrome.
if length>3 print it.
public class palindromeStrings {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String temp="abbppqqwoooopxyz";
int[] table=new int[26];
String alpha="abcdefghijklmnopqrstuvwxyz";
for(int i=0;i<temp.length();i++)
{
table[(temp.charAt(i)-'a')]+=1;
}
pal("",table,alpha,0);
}
public static void pal(String str,int[] table,String alpha, int n)
{
if(n>=3)
{
System.out.println(str);
return;
}
else
{
if(str.length()==0)
{
//System.out.println("yo");
for(int i=0;i<table.length;i++)
{
System.out.println("yo");
if(table[i]==1)
{
table[i]-=1;
pal(str+alpha.charAt(i),table,alpha,n+1);
}
else if(table[i]>=2)
{
table[i]=table[i]-2;
pal(alpha.charAt(i)+str+alpha.charAt(i),table,alpha,n+2);
table[i]=table[i]+2;
table[i]=table[i]-1;
pal(str+alpha.charAt(i),table,alpha,n+1);
}
else
continue;
}
}
for(int i=0;i<table.length;i++)
{
if(table[i]>=2)
{
table[i]=table[i]-2;
pal(alpha.charAt(i)+str+alpha.charAt(i),table,alpha,n+2);
}
}
}
}
}
- amnesiac February 15, 2014One example of external sorting is the external merge sort algorithm, which sorts chunks that each fit in RAM, then merges the sorted chunks together.[1][2] For example, for sorting 900 megabytes of data using only 100 megabytes of RAM:
Read 100 MB of the data in main memory and sort by some conventional method, like quicksort.
Write the sorted data to disk.
Repeat steps 1 and 2 until all of the data is in sorted 100 MB chunks (there are 900MB / 100MB = 9 chunks), which now need to be merged into one single output file.
Read the first 10 MB (= 100MB / (9 chunks + 1)) of each sorted chunk into input buffers in main memory and allocate the remaining 10 MB for an output buffer. (In practice, it might provide better performance to make the output buffer larger and the input buffers slightly smaller.)
Perform a 9-way merge and store the result in the output buffer. Whenever the output buffer fills, write it to the final sorted file and empty it. Whenever any of the 9 input buffers empties, fill it with the next 10 MB of its associated 100 MB sorted chunk until no more data from the chunk is available. This is the key step that makes external merge sort work externally -- because the merge algorithm only makes one pass sequentially through each of the chunks, each chunk does not have to be loaded completely; rather, sequential parts of the chunk can be loaded as needed.
Source : Wiki
One example of external sorting is the external merge sort algorithm, which sorts chunks that each fit in RAM, then merges the sorted chunks together.[1][2] For example, for sorting 900 megabytes of data using only 100 megabytes of RAM:
Read 100 MB of the data in main memory and sort by some conventional method, like quicksort.
Write the sorted data to disk.
Repeat steps 1 and 2 until all of the data is in sorted 100 MB chunks (there are 900MB / 100MB = 9 chunks), which now need to be merged into one single output file.
Read the first 10 MB (= 100MB / (9 chunks + 1)) of each sorted chunk into input buffers in main memory and allocate the remaining 10 MB for an output buffer. (In practice, it might provide better performance to make the output buffer larger and the input buffers slightly smaller.)
Perform a 9-way merge and store the result in the output buffer. Whenever the output buffer fills, write it to the final sorted file and empty it. Whenever any of the 9 input buffers empties, fill it with the next 10 MB of its associated 100 MB sorted chunk until no more data from the chunk is available. This is the key step that makes external merge sort work externally -- because the merge algorithm only makes one pass sequentially through each of the chunks, each chunk does not have to be loaded completely; rather, sequential parts of the chunk can be loaded as needed.
Source : Wiki
public class Singleton {
private static final Singleton instance;
private Singleton(){}
public static Singleton getInstance() {
if (instance == null)
instance = new Singleton();
return instance;
}
}
As you can see, the constructor is private, so we are unable instantiate it in the normal fashion. What you have to do is call it like this:
1
public Singleton singleton = Singleton.getInstance();
When you do this, the getInstance() method then checks to see if the parameter ‘instance’ is null. If it is, it will create a new one by calling the private constructor. After that, it just returns it. Of course, if it is not null, it just returns the existing instance of it. This insures that there is only one copy of the object within your program.
- amnesiac June 17, 2013Psuedocode for probabilityofdead :
float probabilityofdead(int x, int y, int n)
{
if(x>0 && y>0 )
{
if (N-1-x >= n && N-1-y>=n && x>=n && y>=n && n>=0)
return 1;
if( x==N-1 && y>0 && y< N-1 & n>=1)
return 0.25;
if( y==N-1 && x>0 && x< N-1 & n>=1)
return 0.25;
if( x==0 && y>0 && y< N-1 & n>=1)
return 0.25;
if( y==0 && x>0 && x< N-1 & n>=1)
return 0.25;
if(x==0 && y==0 || x==N-1 && y==0 || y==N-1 && x==0 || x==N-1 && y==N-1)
return 0.75;
n--;
return probabilityofdead(x+1,y,n) +
probabilityofdead(x,y+1,n) +
probabilityofdead(x-1,y,n) +
probabilityofdead(x,y-1,n) ;
}
else
return 0;
}
Hence ,probabilityofalive= 1- probabilityofdead
- amnesiac March 01, 2013
Rephollymclark8, Apple Phone Number available 24/7 for our Customers at Accenture
I am clinical laboratory technologist in Stratapro company. I have Excellent clinical laboratory skills, with commended performance conducting/analyzing laboratory ...
Repkarinkwalton, Backend Developer at Broadsoft
I am working as a Support clerk in an MVP Sports company. I love traveling and exploring facts about technology ...
this is correct
- amnesiac September 08, 2015