Min no of +1 operations on array to have only k distinct elements
The ememy of your ememy is friend.Given Q queries of form:
1 person1 person2
2 0 person
person is signified using id
your id is 0
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 enemy
enemy of your's friend enemy and so on
constraints : 0<id<10^5 0<Q<10^5
1 1 2
1 0 1
1 3 4
2 0 1
2 0 2
2 0 4
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
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.
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)
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
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
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].
1<=N,Q<=3*10^5 1<=A[i]<=10^9 1<=L<=R<=10^9
1 2 3 4 5
10 35 15