### ss1073857's blog

By ss1073857, history, 3 months ago,

What will be the time complexity for this code?

public int coinChange(int[] coins, int amount){
if(coins == null || coins.length == 0 || amount < 1) return 0;

Deque<Integer> queue = new ArrayDeque<Integer>();
Set<Integer> visited = new HashSet<Integer>();
int level = 0;

while(!queue.isEmpty()){
int size = queue.size();

while(size-- > 0){
int curr = queue.removeLast();
if(curr == 0) return level;

if(curr < 0) continue;

for(int coin : coins){
int next = curr - coin;
if(next >= 0 && !visited.contains(next)){
}
}
}

level++;
}

return -1;
}


• 0

By ss1073857, history, 21 month(s) ago,

You are given n switches, each switch connected to a led. cost of switch of switch i is ci. intially all leds are on. When any switch is used, all leds in range [i-k,i+k] will get toggled off (on to off, off to on). Find minimum cost to switch off all leds.N<=10000, K<=1000, Ci<10^9

• -2

By ss1073857, history, 22 months ago,

Number of ways to arrange people of type A and type B in a row with k available positions given less than n people of type A can sit consecutively and less than m people of type B can sit consecutively.

• +5

By ss1073857, history, 23 months ago,

Given an array of N numbers with M distinct no . Find minimum no. of numbers such that on permuting those in any order , digit with same value come together. Ex: 1 3 1 5 6 Choosing indices 0 and 1 or 1 and 2 makes all the one’s together So ans: 2 ( two indices are chosen)