gg_ez's blog

By gg_ez, history, 17 months ago, In English

Hey everyone, How to build input test case files for trees and graph questions using random function.

I am not really sure regarding this should I just create an array and insert all elements in a tree or graph data structure or is there any other way as well?

Any help is highly appreciated Thank you

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By gg_ez, history, 20 months ago, In English

My team had registered for ICPC Kanpur prelims but we haven't received the competition mail till now and the contest is tomorrow. Can anyone help me with this?

Thank you

Full text and comments »

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

By gg_ez, history, 20 months ago, In English

You are given a number n and digit d (d <= n <= 10). Your goal is to count all d-digit numbers including 0 to n that are divisible by 3.

The question was asked to me in a company interview and the only logic I gave was from backtracking by rearranging the digits and excluding the case where the left-most number is 0, but the interviewer didn't look much happy with my logic. Is there any better logic for these types of questions in general?

Thanks in advance.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By gg_ez, history, 3 years ago, In English

Argus has to tie a rope around three of the trees, creating a triangular pasture. Its exact shape doesn't matter to Io, but its area is crucial to her. There may be many ways for Argus to arrange the fence, but only the ones which result in different areas of the pasture are interesting for Io. Calculate the number of different areas that her pasture may have. Note that the pasture must have nonzero area.

Assuming the coordinate system one tree will be always fixed at (0 , 1) assume point A while other 2 will be changing i.e. (x1, 0) and (x2, ,0) which i assume to be point B and point C respectively . Which will result in formation of either isosceles triangle or scalene triangle , it can not form equilateral triangle since the range of x will lie in [1 , 50] making angle ABC of minimum of 135 degrees if we take x1 = 1.

With that being done the only option i thought was to use 3 point formula used to find area of a triangle using coordinate geometry i.e. area of any triangle with 3 given points will always be always equal to = abs( x1*(y2 — y3) + a[i]*(y3 — y1) + a[j]*(y1 — y2)) / 2 ( A(x1 , y1) , B(x2, y2) , C(x3 , y3) and i < j ) and if it turn out 0 then that means the points are colinear which is impossible in this question since point A is on OY axis and points B and C are on OX axis .

I am adding a link to help all visualize https://www.mathopenref.com/coordtrianglearea.html

With that being said i coded it and got AC with Time Complexity as O(N^2) If anyone wants to check it out — Submission number #102793428

After the contest ended i saw others solution in which a lot of people used 1/2*base*height where the height is 1 and base is abs(a[j] — a[i]) which also got accepted but to use this formula don`t we have to draw a perpendicular from B on line AC and length of AC then how did it worked??

If anyone has used this method kindly explain it .

Full text and comments »

  • Vote: I like it
  • -17
  • Vote: I do not like it