Блог пользователя Lamentis

Автор Lamentis, история, 9 месяцев назад, По-английски

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?

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

Автор Lamentis, история, 20 месяцев назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится

Автор Lamentis, история, 21 месяц назад, По-английски

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +2
  • Проголосовать: не нравится