jankit366's blog

By jankit366, history, 3 months ago, In English

A and B wants to reach some destination in an undirected graph using the least number of unique edges. Find the count of unique edges.

Let's say the two paths come out to be this.. A-x-y-D B-y-D

Output : 4

Explanation : A-x, x-y, y-D and B-y

Follow up: What if there are multiple sources?

Can someone help me to solve this optimally?

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By jankit366, history, 4 months ago, In English

Given an array { 1, 7, 7, 2,3, 7, 6,-20}. Find the longest nondecreasing contiguous sequence with substitution. we can substitute any array element with any integer such as all occurences of 7 replaced with 1. In this way new array would be { 1,1,1,2,3,1,6,-20}. Only one substitution is allowed.

What can be the optimal solution for this?

Can someone help me with the approach?

Full text and comments »

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