Open In App

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: 

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:

Output format:

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

Article Tags :