Lamentis's blog

By Lamentis, history, 17 months ago, In English

Can someone explain when to use which variation of equality in Binary Search:

1.)while(l<=r) 2.)while(l<r) 3.)while(r-l>1)

Generally, I use the first one as it seems to be the most comfortable for me. However, when going through other participants' codes, I often see the other two variations. Is there any difference?

Full text and comments »

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

By Lamentis, history, 2 years ago, In English

This question came in the recent summer internship drive on my campus but I could not solve it

Q)Array contains only 0 and 1. You are given two integers X and Y. Count how many subarrays have (count of 0) to (count of 1) equal to X: Y.

1<=N<=1e5 1<=X,Y<=1e5

Please help. Thanks

Full text and comments »

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

By Lamentis, history, 2 years ago, In English

Q) Given a 2D array of size n that represents the x and y coordinates([x,y]), find the number of collinear triplets.If collinear triplets>1e9, then return -1.

N<=1000

----------------------------------------------- This question came in yesterday's Microsoft OA. I was not able to come up with an efficient solution and ultimately wrote an O(n^3) solution using the idea that the area of triangle formed by three collinear points is 0.

Please suggest an efficient solution.

Full text and comments »

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