GOCC18: Google Online Coding Challenge 2020 – New Grad(India)

The Google online challenge(GOCC 18) 2020 for new graduate 2021 was held on September 26, 2020.

It was a 60-mins online test and 2 coding questions to solve. The exam was conducted on HackerEarth platform.

The process is that first your resume should be shortlisted for the exam.

Duration of the exam – 1hr

First question: RANGE OF QUERIES



You are given an array A with N integers. You are required to answer Q queries of the following type:

L R

Determine the count of distinct prime numbers that divides all the array values from index L to R.

NOTE: Consider 1-based indexing

Input format: 

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N.
  • The second line of each test case contains N space-separated integers denoting A.
  • The third line contains integer Q.
  • Next, Q lines contain two space-separated integers denoting the queries.

Output Format;

Print the count of distinct prime numbers that divides all the array values from index L to R.

Experience: I have solved this using segment trees https://www.geeksforgeeks.org/segment-tree-set-1-range-minimum-query/ see this article on range minimum query, it is similar to this problem.



Second Question – THE VALUE OF A WEIGHTED TREE

You are given a weighted undirected tree with N nodes. Every edge has a weight associated with it.

You are required to find the value of ∑(i=1 to N-1) ∑(j=i+1 to N) F(i,j) function where F(i,j) denotes the sum of weights of edges on a simple path between node i and j.

Input format:

  • The first line contains an integer T denoting the number of test cases.
  • The first line of each test case contains an integer N denoting the number of nodes in the tree.
  • Next N-1 lines contain three space-separated integers u v w denoting an edge between u and v with weight w.

Output format:

For each test case, print the value of function modulo 10^9 + 7 in a new line.


Write your Interview Experience or mail it to contribute@geeksforgeeks.org

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.