erkejriwal
BAN USERwe can impliment it by graph bfs.
public void snackAndLadderProblem(){
Integer[] map = new Integer[30];
map[2]=21;
map[4]=7;
map[10]=25;
map[19]=28;
map[16]=3;
map[18]=6;
map[20]=8;
map[26]=0;
int minDiceThrown = 30;
System.out.println("min steps needed to finish snack and ladder game:-
"+this.snackAndLadderCheckForNextSixElement(map, minDiceThrown, 0, 0));
}
private int snackAndLadderCheckForNextSixElement(Integer[] map, int
minDiceThrown, int startingPoint, int currentCountOfDiceThrown){
if(currentCountOfDiceThrown > minDiceThrown){
return minDiceThrown;
}
for (int i = 1; i <= 6; i++) {
int currentIndex = startingPoint+i;
if(currentIndex >= map.length){
return currentCountOfDiceThrown+1;
}
if(currentIndex < map.length && map[currentIndex]!= null ){
int diceThrownAfterThisDip =
this.snackAndLadderCheckForNextSixElement(map,
minDiceThrown, map[currentIndex], currentCountOfDiceThrown+1);
if(diceThrownAfterThisDip < minDiceThrown){
minDiceThrown = diceThrownAfterThisDip;
}
}
}
int lastIndex = startingPoint+6;
while(lastIndex > map.length || map[lastIndex]!=null){
lastIndex--;
}
int diceThrownAfterThisDip =
this.snackAndLadderCheckForNextSixElement(map, minDiceThrown,
lastIndex, currentCountOfDiceThrown+1);
if(diceThrownAfterThisDip < minDiceThrown){
minDiceThrown = diceThrownAfterThisDip;
}
return minDiceThrown;
}
Hi,
I think observer pattern will work fine.
Interface CricMatch{
}
class CricMatchImpl impliments CricMatch{
List<Observer> list;
updateAllUsers(){
//iterate through list and send update
}
}
Interface Observer{
update();
}
class ObsrverImpl impliments Observer{
update (){
// display change code
}
}
Running code is given below.Enjoy!
public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet<String> set = new HashSet<String>();
String current ="";
System.out.println(findWay("rrlrlr",current, set,0, 0, 1));
}
public static int findWay(String patt, String current,HashSet<String> set,int index, int
value, int difference){
int count = 0;
if(index == patt.length() && value == difference){
if(set.contains(current)){
return 0;
}else{
System.out.println(current);
set.add(current);
return 1;
}
}else if(index == patt.length()){
return 0;
}
count += findWay(patt,current,set, index+1, value, difference);
if(patt.charAt(index)=='r'){
value++;
current = current+"r";
}else{
value--;
current = current+"l";
}
count += findWay(patt,current,set, index+1, value, difference);
return count;
}
Output Will be:-
r
rlr
lrr
rrl
rlrlr
rrllr
rrlrl
7
min heap will work fine, insert first n elements into heap, now stream of integer is on fire, as we get new integer we compare with min of min heap, if it is more than this we remove min and insert this new element so time complexity for one insertion will be lon(n), let total stream integers are G so over all time complexity will be G.lon(n), million no's, means 10^6 elements so min heap will work fine.
- erkejriwal June 20, 2017I think question is saying
we have two type of containers
let x and y,
let total are 5 containers in each type
x type has 1,2,3,4,5 capacities containers
y has 1,2,3,4,5 capacities containers
let cost to transfer from x to y is given as
y1 y2 y3 y4 y5
x1 3 4 2 1 0
x2 * 2 3 1 4
x3 * * 1 3 2
x4 * * * 2 1
x5 * * * * 3
* indicates that transfer from bigger container to smaller not possible
Answer:-
i think we can solve it by using dp
that transfer content of X1 into Y1 and proceed further, find total cost, then x1 to y2 for each such case find total cost and find min of these total costs.
Rephenryhokinsh, Android test engineer at ABC TECH SUPPORT
I’m Henry, I am Children's librarian in Rolling Thunder .My Work involves the responsibility for supervising the children ...
RepHi, I am Maria from Worcester, USA. I have been working as a Blogger in Enticing Express from last 2 ...
we can create a priority queue in which jobs will be inserted and if any part of a job throw an exception for which new job should be added then we can add that job in this priority queue, priority of jobs will be decided based on timing (at what time job should run) and job priority (two jobs at same time than which job should run prior),
- erkejriwal September 14, 2017