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

Автор DaviddeGea1, история, 5 лет назад, По-английски

I got this question in a company's coding round:

Find the minimum cost to make all the elements of an array equal, when 2 operations can be performed-

  1. Increment an element by 1 which costs 'a' units
  2. Decrement an element by 1 which costs 'b' units

Constraints:

Array size <= 10^5

a,b <= 10^5

0 <= element <= 10^6

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

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

Автор DaviddeGea1, история, 5 лет назад, По-английски

I got this problem in an off-campus round, someone please help me solve the problem:

You are given N elements, each having unique values. If you distribute them among 2 children in such a way that the total unique value that each child receives must be greater than K. How many ways can you distribute the elements so that the mentioned condition holds true?

Since the answer can be very large print it modulo 1e9+7.

1 <= N <= 10^3

1 <= K <= 10^5

1 <= A[i] <= 10^9

Sample Input:

3 5

3 7 4

Sample Output:

2 -> {3,4},{7} and {7},{3,4}

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

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

Автор DaviddeGea1, история, 5 лет назад, По-английски

I get really confused at times at to which graph algorithms is specific to directed(or undirected) graphs or can be applied to both. So just wanted to create a blog that will contain all the graphs algorithms and their area of application(Directed, undirected or both).

I'll start with some about which I'm sure of:

  • DFS, BFS : Both

  • Topo sorting : Directed

  • Dijkstra : Both

  • Prims, Kruskal : Both

Please add more algorithms and/or correct me if I'm wrong.!

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

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