DaviddeGea1's blog

By DaviddeGea1, history, 4 years ago, In English

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

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it

By DaviddeGea1, history, 4 years ago, In English

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}

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it

By DaviddeGea1, history, 4 years ago, In English

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.!

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it