Блог пользователя ss1073857

Автор ss1073857, история, 22 месяца назад, По-английски

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>();
    queue.addFirst(amount);
    visited.add(amount);
    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)){
            queue.addFirst(next);
            visited.add(next);
          }
        }
      }

      level++;
    }

    return -1;
  }

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор ss1073857, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

Автор ss1073857, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

Автор ss1073857, история, 4 года назад, По-английски

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)

Полный текст и комментарии »

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится