jd_sal's blog

By jd_sal, history, 3 days ago, In English,

Given an array of integers say A and a number k.One operation means choosing an index i of array and increasing A[i] by 1.You can use this operation on a particular index multiple times.You perform at most k operations(not necessarily on a single index) on this array after which some number X is repeated maximum number of times say Y, then print Y,X.If for a Y, multiple X exist then print the smallest such X. For example let A=[1,9,11,19] and k=10. We can form [9,9,11,19],[1,11,11,19],[1,9,19,19] so answer will be X=9, Y=2.

Constraints : A.size()<=10^5 and 0<=K<=10^9 and -10^9<=A[i]<=10^9.

I can do it in O(n^2) but it's obviously not optimal. Any idea how to proceed?

It's not from any ongoing contest.

Read more »

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

By jd_sal, history, 2 months ago, In English,

Problem statement : Given an array of integers A of size N. An array is called power array if floor(maximum of array/2) >= all other elements of array. E.g [5,3,6,13] is a power array since 13/2 >= 5,3,6. Calculate how many subarrays of A are Power Arrays. Note : Single element can never be a power array.Constraints : 1<=N<=10^5 , 1<=A[i]<=10^5 .

I can think of a O(n^2) solution but it will definitely timeout. Any efficient solution? P.S : It's from a contest which has ended!

Read more »

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

By jd_sal, history, 2 months ago, In English,

Hello all, Recently a contest was held on interviewbit named Codersbit.I am attaching the problems. Please help me with the problems, I was able to do few of them but not in the most optimal way.And the contest ended few days ago, so it's not cheating.

1.(https://imgur.com/gn8I33P) (https://imgur.com/Ik8iLJs)

2.(https://imgur.com/KOrRzc8) (https://imgur.com/k1MBeYq)

3.(https://imgur.com/69KNRNf)

4.(https://imgur.com/3IGFu87) (https://imgur.com/zoNJ2CM)

5.(https://imgur.com/VplmGqS)

Read more »

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