### aya1909's blog

By aya1909, history, 5 months ago,

Min no of +1 operations on array to have only k distinct elements

• -6

By aya1909, history, 5 months ago,

The ememy of your ememy is friend.Given Q queries of form:

1 person1 person2

2 0 person

person is signified using id

for query of type 2 print following:

-1 if person is your enemy

1 if person is your friend

0 if person is not related to you

A person is your friend if he is:

enemy of your's friend enemy and so on

constraints : 0<id<10^5 0<Q<10^5

example:

1 1 2

1 0 1

1 3 4

2 0 1

2 0 2

2 0 4

output:

-1

1

0

• -14

By aya1909, history, 5 months ago,

Given two binary strings of equal length (eg. "10101" and "10010") we had to find whether we can convert string 1 to string 2 by performing following operations:

reverse substring of length 2 reverse substring of length 2 reverse substring of length 2

• 0

By aya1909, history, 5 months ago,

Given a range [l r] find the sum of last digits of fibonacci numbers between l and r. i.e , last(fib(l))+last(fib(l+1)) .... last(fib(r)),

where last(fib(a)) denotes last digit of ath fibonacci number.

1<=l<=r<=1e9

• 0

By aya1909, history, 6 months ago,

Given an array, choose two contiguous non-overlapping arrays, such that all elements are strictly increasing. Return the maximum length possible for this combination.

Ex: 7 1 2 4 6 5 3 8 9 10 => ans: 7 (Choose 1 2 4 6 & 8 9 10)

• -9

By aya1909, history, 6 months ago,

given a number n, convert it into k such that k has all even digit with minimum no of operations. 1 operation is either increment or decrement n by 1.

example: Input 11 output -> 3 Input 199 output -> 1 Input 2018 output -> 2

• +3

By aya1909, history, 6 months ago,

what will happen if i run kruskal algorithm on disconected graph?? Actual problem is given n disconnected undirected graphs find kth largest value of mst of all graphs

• -9

By aya1909, history, 6 months ago,

You are working in Samara, Russia for a few days. Each day has a new pay per unit of work and a new cost per unit of food. Working 1 unit costs 1 unit of energy, and eating 1 unit of food adds 1 unit of energy. Here are some specifications of your employment:

You arrive with no money, but with energy. You can never have more energy than you arrive with, and it can never be negative. You can do any amount of work every day (possibly not do any work at all), limited only by your energy. You cannot work when your energy is zero. You can eat any amount of food every day (possibly not have any food at all), limited by the money you have. You cannot eat when the money you have is zero. You can eat food at the end of the day, and cannot return to work after eating. You can return to work the next day. Your true goal is to return home with as much money as possible. Compute the maximum amount of money you can take home.

Input: N = 3, Earning=[1, 2, 4], Cost[]=[1, 3, 6], E = 5 Output: 20

• +2

By aya1909, history, 6 months ago,

Help needed to solve this problem. It was asked in an online assessment of a company. Here is the link:- [https://stackoverflow.com/questions/63972021/what-is-the-algorithm-for-this-programming-question]

• 0

By aya1909, history, 6 months ago,

How to count total no. of distinct cycles in an undirected graph. Graph may be disconnected. Constraints: 0<= no. of nodes <=10

Answer for given image is 7

• -32

By aya1909, history, 7 months ago,

You Are given an array A of N integers. You have to answer Q queries of form L R. Answer to each query is sum of lengths of all sub arrays in A whose maximum element lies in range [L,R].

Constraints:

1<=N,Q<=3*10^5 1<=A[i]<=10^9 1<=L<=R<=10^9

Input:  5 3   1 2 3 4 5   1 3   1 5   5 5

Output:

10 35 15